In my way of brushing questions, python first quickly grasps the algorithm ideas, and on this basis, tries multilingual solutions according to needs.
table of Contents:
- Arrays
- Map
- Math
- String
- List
- Vector
- Queue
- Set
- Stack
Arrays usage:
- Arrays.copyOf (array, length) copy algorithm
- Arrays.sort (double []) sort in ascending order
- Arrays.asList (arr) .contains () Determine whether the array contains an element
Map usage:
5. Map <T, T> map = new HashMap <
6. Map.get (key): get value
7. Map.getOrDefault (Object key, V defaultValue): equivalent to setdefault
8. Map in python . put (key, value): add key-value pairs
9. Map.keySet (): all key value sets in the map
Math usage:
10. Math.max (Array) gets the maximum value
11. Math.abs () gets the absolute value
10. Math.pow () gets the exponent
String:
- Integer.parseInt (str): string to number
- str.length (): string length
- str.charAt (i): Get the ith character of a string
- str1.compareToIgnoreCase (str2): String comparison ignoring size
- str1.compareTo (str2): String comparison ignoring size
- str.equals (String ostr): Determine whether two strings are equal
- str.indexOf (ch): Find where the character / string appears
- str.substring(beginIndex, endIndex)
- str.split (regular expression): save the split result in a string array
- str1.concat (str2): merge str1 and str2
- str.toLowerCase (): Convert all strings to lowercase
- str.toUpperCase (): Convert all characters to uppercase
- str.trim (): Ignore leading and trailing spaces
- str.replace(lodeChar, newChar)
- str.split (): The return value is a string array
- str.toCharArray()
StringBuilder:
append (parameter): append content to the end of StringBuilder
insert (position, parameter): insert content into the specified position
toString: StringBuilder into String
int length: length
List:
- List person = new ArrayList <> (): mostly used for searching through traversal
- LinkedList person = new LinkedList (); mostly used to insert and delete
- add (obj): add an element
- remove (index / obj): remove the element
- get (index): get the element
- size: Get length
- set (index, target): modify the element value at the index
- Collections.sort(List<> l)
Vector
- Vector add (int index, Object element): add at the specified position
- add (Object o): add to the end
- addAll (Collection c): Join in the order of collection iteration
- int capacity (): returns the current capacity
- void clear (): clear all elements
- clone (): clone a copy
- elementAt (int index): Returns the component at the specified index.
- Object get (int index): Returns the element at the specified position in the vector.
- boolean isEmpty()
Queue
- add add a meta cable if the queue is full, throw a IIIegaISlabEepeplian exception
- remove removes and returns the element at the head of the queue. If the queue is empty, a NoSuchElementException is thrown
- element returns the element at the head of the queue. If the queue is empty, a NoSuchElementException is thrown.
- offer add an element and return true if the queue is full, return false
- poll removes and returns the element at the head of the queue. If the queue is empty, returns null
- peek returns the element at the head of the queue or null if the queue is empty
- put adds an element and blocks if the queue is full
- take removes and returns the element at the head of the queue. If the queue is empty, block
Set
- Set seen = new HashSet();
- Set.add (): add elements
- Set.contains (value): determine whether the set contains value
Stack
- boolean empty()
- Object peek( )
- Object pop( )
- Object push(Object element)
- int search(Object element)
other:
- String.valueOf (n) .toCharArray (): Number to character array
- PriorityQueue pq = new PriorityQueue((k1, k2) -> grid[k1 / N][k1 % N] - grid[k2/N][k2%N]);