Leetcode List

Onsite talk

1.了解自己的项目细节

Question:

1.思考BST level order traverse 什么时候不用记录size?

  1. HashTable 有啥用来着?

Note :

String[] array = new String[] {"lint", "intl","code"};
arraylist.set(index , Element);
Str.startsWith(string) 【Return true/false】

list.indexof(返回的是index啊
!!!)
list.get()返回的才是值啊!!

时刻谨记:substring的用法!
str.substring(start, length)
Chars beginning at start
Up to but not including end

神句!
map.put( c , map.getOrDefault(c , 0) + 1);

  //遍历

Map map = new HashMap();

//遍历map中的键

for (Integer key : map.keySet()) {

System.out.println("Key = " + key);  

}

//遍历map中的值

for (Integer value : map.values()) {

System.out.println("Value = " + value);  

}

    int i = Arrays.binarySearch(dp, 0, len, x);
      returns the index if contains. else return:
    【it returns (-(insertion point) - 1) 】

int count = Character.getNumericValue(char c); =========》char
Integer.parseInt() ========》String

    private Queue small = new PriorityQueue();
  默认出的是最小的,有null的时候感觉会出null,因为system.out.print 会报错

PriorityQueue(int initialCapacity, Comparator comparator)
Character.isLowerCase

    HashSet 真是个好东西,只记录有无这个值,不管重复多少次。   
    ArrayList: .size()
    String : .length()
    int[]num: .length
    hashTable.length;

    Integer.MAX_VALUE;
    Integer.MIN_VALUE;
    Arrays.sort(num);
    Arrays.fill( num, i);
    Collections.reverse(result);

    HashSet set = new HashSet<>();  set.size(); set.add(); set.contains();

    HashMap map = new HashMap<>(); map.put(); map.containsKey();
    map.keySet(); 返回一套key!!~

    HashTABLE :  ListNode[] hashtable = new ListNode[newCapacity];

    char[] array= str.toCharArray();

    Queue q = new LinkedList();
    Stack s = new Stack<>();
    s.pop();
    s.push(1);
    s.peek();

    q.add(1);
    q.offer(1);
    q.poll();
    q.peek();

位运算操作:

  A&B : 都是1则为1,否则为0 ========> 可以得到A和B中所有该进位的地方(都是1才进位)
  进位: A&B << 1
  << :移位运算符,所有的二进制像左移一个,末尾舔0.(相当于十进制乘以了2) 

  byte的取值范围为-128~127,占用1个字节(-2的7次方到2的7次方-1)
  short的取值范围为-32768~32767,占用2个字节(-2的15次方到2的15次方-1)
  int的取值范围为(-2147483648~[2147483647](https://www.baidu.com/s?wd=2147483647&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YvPjR4mWuWnHnvPjuhPHbk0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErHb4PHDznWT)),占用4个字节(-2的31次方到2的31次方-1)
  long的取值范围为(-9223372036854774808~9223372036854774807),占用8个字节(-2的63次方到2的63次方-1)

Easy

1.Sort Integers
2.Binary Tree Maximum node
3.Fibonacci
4.Rectangle Area
5.Remove LinkedList Element
6.A+B problem
7.Guess Number Game
8.Intersection of Two Arrays
9.Intersection of Two Arrays II

Chapter 1 Sort

Jun 19
1.Median (Quick sort)
July 3
2.StrStr(自己的方法。有时间再复习答案的方法)

Chapter 2 Binary Search

1.First Position of Target
3.Search Insert Position (注意end+1的情况)
4.Search a 2D Matrix
5.Find Peak Element(以mid为最低点看两边+1的趋势即可。但是要考虑else的情况,随便分配给start或者end 都可以。不分配的话死循环了。)
6.First Bad Version
July 16
1.Search in Rotated Sorted Array
2.Search in Rotated Sorted Array II
3.Find Minimum in Rotated Sorted Array(一定是nums[mid] > nums[end]
而不是nums[mid] >= nums[start]
)
4.Find Minimum in Rotated Sorted Array II
5.Search for a Range
6.Binary Search Tree Iterator(用stack)
7.Insert Node in a Binary Search Tree
8.Remove Node in Binary Search Tree
9.Search Range in Binary Search Tree
10.Convert BST to Greater Tree

Chapter 3 Binary Search Tree

Binary Search Tree 的定义: 左< 中 < 右

25.Binary Tree Inorder Traversal
26.Binary Tree Postorder Traversal
27.Binary Tree preorder Traversal
28.Binary Tree level order Traversal
29.Binary Tree Level Order Traversal II
30.Binary Tree Paths(String的相加:直接用加号相加)
31.Binary Tree Path Sum(1.考虑负数情况 2.题目说了要到达leaf)
Jun 19
5.Count of Smaller Number (Segement Tree 的解法???!)
6.Segment Tree Build( Segment Tree
7.Segment Tree Modify
Jun 20
1.Segment Tree Query
2.Segment Tree Query II
Jun 23
1.Maximum Depth of Binary Tree
2.Minimum Depth of Binary Tree (Path 一定是要到达leaf的)
3.Validate Binary Search Tree
4.Lowest Common Ancestor
5.Binary Tree Zigzag Level Order Traversal

July 11
6.Balanced Binary Tree

Chapter 4 D&Q

July 6
1.Triangle : (自上而下遍历的时候呢,注意第一条不能算进去,而且,最后一条也不能算呀)
O(n) 的方法:自下而上,res[0][0] = res[0][0+1]+ res[0+1][0+1] +triangle[0][0]。。。递归每次只保留最小值
2.Minimum Path Sum

July7
3.Climbing Stairs
4.Unique Paths
5.Unique Paths II

July10
1.Binary Tree Maximum Path Sum (简洁优雅的leetcode)
2.Jump Game
3.Jump Game II
4.Longest Increasing Subsequence( Arrays.BinarySearch() )
5.Longest Common Subsequence (用二维数组来做,你敢信吗 或许有图的概念在里面?)
6.Longest Common Substring(思考这一题dp的推导公式
7.valid Palindrome
8.Palindrome Partitioning

July11
1.Palindrome Partitioning II (又用了二维格子,interesting )
2.word break(注意i和j ,不要用最简单的从前往后,而是从j到i)

July14
3.Distinct Subsequences(用二维格子)
4.Edit Distance(用二维格子)
5.Interleaving String ((用二维格子,这是目前最难的

Chapter 7 Graph

Graph 掌握重点:

  1. clone graph
  2. Topological Sorting
  3. Search:
    A. DFS : 递归,(二叉树,D&Q : DP问题是试图把2^n或者n!===> n^2, n^3)
    O(2^n),O(n!)
    find all possible solutions : Permutations / subsets
    B. BFS:level order (while)
    O(n)====> Binary Search Tree, O(m) ====>Graph
    //n 是点,m 是边
    graph traversal
    find shortest path in a simple graph

6.clone Graph
7.classical binary search
8.Topological Sorting
9.Permutations
10.subsets
11.N-Queens
12.Valid Palindrome
13.Palindrome Partitioning
14.Combinations
15.Combination Sum
16.word ladder
17.word Ladder2

Chapter 8 Data Structure

1. Stack

18.Minstack
19.Implement Queue by two Stacks
20.Largest Rectangle in Histogram
21.max Tree (!)

2. Hash

Operations:
Insert/ Delete/ Search : O(1)

Collision :
Open Hashing(LinkedList)
Closed Hashing(Array)

因此为了避免collision,要尽量离散

Java differences of :
HashTable / HashSet / HashMap
HashTable is thread Safe

22.rehashing
23.Longest Consecutive Sequence (不用考虑array是否sort,在hashset里找到一个删去一个就好了。hashset 的意义本身就是记录是否contain的)
Jun.7
24.LRU Cache (#DataStructure: LInkedHashMAp

Chapter 9 High Frequence

33.Single Number (异或运算 ^ : 不进位的二进制加法)
34.Single Number 2
35.Single Number 3
40.Majority Number
Jun.19
2.Majority Number 2
3.Majority Number 3
Jun.30
1.Data Stream Median (Heap : log(n) )
2.Best Time to Buy and Sell Stock
3.Maximum Subarray
4.Minimum Subarray
5.Maximum Subarray 2
6.Best Time to Buy and Sell Stock 2
7.Best Time to Buy and Sell Stock 3
8.Two sum( Return index 基本上只能用hash表 )
(** 返回数值的话,是Two pointer问题** )
9.Maximum Subarray Difference(只通过了百分之64,要参考求min时的做法)10.3_SUM(Two Pointer)(未跑通)
July.1
1.4_SUM(未做)
2.3-SUM closet (未做)
July.3
1.Partition Array (背诵)
2.Sort Letters by Case
3.sort color 1
4.sort color 2
5.Interleaving positive and negative
6.Sqrt(二分法。变量是long)
7.Fast Power (二分法。不是很明白这个数学运算,背诵

你可能感兴趣的:(Leetcode List)