雙指針和codetop復習
- 1.雙指針
- 1.[移動零](https://leetcode.cn/problems/move-zeroes/description/)
- 遞歸
- 1.[計算布爾二叉樹的值](https://leetcode.cn/problems/evaluate-boolean-binary-tree/)
- 2.[Pow(X,n)](https://leetcode.cn/problems/powx-n/)
- 3.[兩兩交換鏈表中的節點](https://leetcode.cn/problems/swap-nodes-in-pairs/description/)
- 動態規劃
- 1.[不同路徑](https://leetcode.cn/problems/unique-paths/description/)
- 2.[不同路徑II](https://leetcode.cn/problems/unique-paths-ii/description/)
- 貪心
- 1.[最大數](https://leetcode.cn/problems/largest-number/description/)
1.雙指針
1.移動零
//創建雙指針,cur=0,dest=-1,
//cur的作用,掃描數組,nums[cur]==0,cur++ nums[cur]!=0時,再處理
//這樣就把數組分成三個部分,[0,dest]:已經處理的[dest+1,cur-1]:里面全部是0,[cur,size]:全是待處理的部分
遞歸
1.計算布爾二叉樹的值
2.Pow(X,n)
//這種暴力遞歸不可取,計算 myPow(x, n) 時,需要遞歸 n 次(比如 n=10000 就要遞歸 10000 層)。當 n 很大(比如 n=1e9),會觸發棧溢出或超時
//這道題叫快速冪,所以在上面的暴力做優化,每次都算n的一半,比如n=10,第一次算n=5,第二次算n=2,這樣就可以達到快速降冪
3.兩兩交換鏈表中的節點
//提前保存要返回的指針也就是第一次head->next,然后只交換節點中的val,然后head向后走兩步
動態規劃
1.不同路徑
//mn,但是開(m+1n+1),把(0,1)或者(1,0)初始化為1
2.不同路徑II
貪心
1.最大數
//先把所有數字to_string到vector ,然后把里面的所有string用sort(默認升序)排序,用sort時,重新寫下排序規則 [](string s1,string s2){return s1+s2>s2+s1}