2019.11.17
LC217.ContainsDuplicates:
Arrays.sort() has in general O(NlogN) time complexity
with different threshold it will choose from
InsertionSort, QuickSort and MergeSort
Review on the HashMap Function:
Map<Character, Integer> hm = new HashMap<>();
char ch = s.charAt(i);
hm.put(ch, hm.getOrDefault(ch, 0) + 1 );
//hm.getOrDefault(hm.get(ch),0) +1 XXXwrong!!
//key is ch.
//
Character.isLetterOrDigit();
//
Character.isLetter();
Character.isDigit();
//
String s = "xxx";
s = s.replaceAll(" ", "");
s = s.toLowerCase();
s = s.trim()//delete spaces in the start and in the end
//
s.substring(a,b);
returns a string from index a to index b - 1 of s
//
int to char: (char)(a + '0') //a as int
char to int: int test = Character.getNumericValue(c) //c as char
char to string: c + ""//c as char
string to char: s.charAt(index) //s as string
or char[] chars = s.toCharArray()
//
double d = (double)a; // a as int
//
with different object, use a.equals(b) instead of a == b
//
for String, can not iterate as follows:
//
for(Character c : s) XXX
//
remember to import java.util.*;
//
list.remove(3); //remove index 3
list.remove(new Integer(3)) //remove object 3, assuming the data type is Integer