1. 程式人生 > >LeetCode解題報告彙總! All in One!

LeetCode解題報告彙總! All in One!

作者: 負雪明燭
id: fuxuemingzhu
個人部落格: http://fuxuemingzhu.cn/


把自己刷過的所有題目做一個整理,並且用簡潔的語言概括了一下思路,彙總成了一個表格。

題目的排列順序是按照先Easy再Medium再Hard排列的,暫時還沒有把題目全部整理完成。後序我會把刷過的所有的題目都整理到這個文件裡。

題目 難度 解法 題目地址
566. Reshape the Matrix Easy 變長陣列,求餘法,維護行列計算在新的陣列中的位置 https://blog.csdn.net/fuxuemingzhu/article/details/83626519
897. Increasing Order Search Tree Easy 直接中序遍歷的結果放到連結串列結尾 https://blog.csdn.net/fuxuemingzhu/article/details/82349263
771. Jewels and Stones Easy 字典統計次數 https://blog.csdn.net/fuxuemingzhu/article/details/79188903
929. Unique Email Addresses Easy 字串+set統計個數 https://blog.csdn.net/fuxuemingzhu/article/details/83478570
709. To Lower Case Easy ASIIC碼操作ord,chr https://blog.csdn.net/fuxuemingzhu/article/details/81015228
804. Unique Morse Code Words Easy 字典對映 + set統計個數 https://blog.csdn.net/fuxuemingzhu/article/details/79774003
905. Sort Array By Parity Easy 自定義sorted函式的cmp為數字mod 2 https://blog.csdn.net/fuxuemingzhu/article/details/82732066
461. Hamming Distance Easy 先異或 再數1的個數 https://blog.csdn.net/fuxuemingzhu/article/details/54138423
657. Robot Return to Origin Easy Counter統計,判斷是否相等 https://blog.csdn.net/fuxuemingzhu/article/details/83663650
832. Flipping an Image Easy 直接計算新的陣列的每個位置的值即可 https://blog.csdn.net/fuxuemingzhu/article/details/80471495
617. Merge Two Binary Trees Easy 樹的遞迴操作 https://blog.csdn.net/fuxuemingzhu/article/details/79052953
28. Implement strStr() Easy 字串遍歷+切片是否相等的判斷 https://blog.csdn.net/fuxuemingzhu/article/details/79254558
890. Find and Replace Pattern Easy 直接使用字典做對映 https://blog.csdn.net/fuxuemingzhu/article/details/82014687
814. Binary Tree Pruning Medium 二叉樹的後序遍歷 https://blog.csdn.net/fuxuemingzhu/article/details/79858752
561. Array Partition I Easy 排序+求和 https://blog.csdn.net/fuxuemingzhu/article/details/71412574
728. Self Dividing Numbers Easy 直接遍歷區間的每個數字進行判斷 https://blog.csdn.net/fuxuemingzhu/article/details/79053113
852. Peak Index in a Mountain Array Easy 二分查詢的變種,使用Mid位置和左右位置比較 https://blog.csdn.net/fuxuemingzhu/article/details/80721162
922. Sort Array By Parity II Easy 分別求出奇偶陣列然後拼接 https://blog.csdn.net/fuxuemingzhu/article/details/83045735
883. Projection Area of 3D Shapes Easy 分別計算三檢視的面積即可 https://blog.csdn.net/fuxuemingzhu/article/details/81748335
908. Smallest Range I Easy 直接數學計算 https://blog.csdn.net/fuxuemingzhu/article/details/82824685
867. Transpose Matrix Easy 先構建陣列再遍歷實現翻轉 https://blog.csdn.net/fuxuemingzhu/article/details/81015450
589. N-ary Tree Preorder Traversal Easy 多叉樹的先序遍歷,可以用遞迴和迭代 https://blog.csdn.net/fuxuemingzhu/article/details/81021950
590. N-ary Tree Postorder Traversal Easy 多叉樹的後序遍歷 https://blog.csdn.net/fuxuemingzhu/article/details/81017965
350. Intersection of Two Arrays II Easy 先排序然後用兩個指標移動找出陣列交集 https://blog.csdn.net/fuxuemingzhu/article/details/54341965
876. Middle of the Linked List Easy 快慢指標同時向連結串列後面移動 https://blog.csdn.net/fuxuemingzhu/article/details/81748484
700. Search in a Binary Search Tree Easy BST中節點的查詢,遞迴 https://blog.csdn.net/fuxuemingzhu/article/details/81015754
933. Number of Recent Calls Easy 找出滿足一定條件的區間長度,可以使用二分或者佇列 https://blog.csdn.net/fuxuemingzhu/article/details/83714891
559. Maximum Depth of N-ary Tree Easy 求樹的高度,可以使用BFS和DFS https://blog.csdn.net/fuxuemingzhu/article/details/81021864
557. Reverse Words in a String III Easy 字串的單詞分別翻轉再拼接到一起就好了 https://blog.csdn.net/fuxuemingzhu/article/details/70141268
806. Number of Lines To Write String Easy 使用字典儲存每個字元的長度,然後統計每行的長度是否超過100就好了 https://blog.csdn.net/fuxuemingzhu/article/details/79810381
344. Reverse String Easy 字串翻轉,[::-1 https://blog.csdn.net/fuxuemingzhu/article/details/51284382
811. Subdomain Visit Count Easy 字典儲存每個子域名出現的次數即可 https://blog.csdn.net/fuxuemingzhu/article/details/79789925
476. Number Complement Easy 求數字的補數,方法是異或上與其二進位制數字的長度相等的全1二進位制數 https://blog.csdn.net/fuxuemingzhu/article/details/54562124
821. Shortest Distance to a Character Easy 過兩遍陣列,分別找出距離左邊和右邊的這個字元的最短距離 https://blog.csdn.net/fuxuemingzhu/article/details/80471765
500. Keyboard Row Easy 使用字典儲存每行元素,然後看每個單詞是不是隻由一行元素組成 https://blog.csdn.net/fuxuemingzhu/article/details/68953517
893. Groups of Special-Equivalent Strings Easy 把奇偶位置都取出來,重新拼接成字串作為指紋,看總的有多少種指紋 https://blog.csdn.net/fuxuemingzhu/article/details/82083609
872. Leaf-Similar Trees Easy 先序、中序、後序都能得到葉子序列 https://blog.csdn.net/fuxuemingzhu/article/details/81748617
884. Uncommon Words from Two Sentences Easy 使用字典統計每個單詞出現的次數,然後看字典keys()的交集,然後在字典中看是不是隻出現了一次 https://blog.csdn.net/fuxuemingzhu/article/details/81749170
766. Toeplitz Matrix Easy 判斷每個斜線是否相等,方法是判斷每個元素是否和其左上角元素相等 https://blog.csdn.net/fuxuemingzhu/article/details/79127213
463. Island Perimeter Easy 求小島的周長。使用所有陸地個數×4-相交部分×2. https://blog.csdn.net/fuxuemingzhu/article/details/83868905
682. Baseball Game Easy 用一個棧進行模擬 https://blog.csdn.net/fuxuemingzhu/article/details/79183412
868. Binary Gap Easy 二進位制表示中1的最大間距,保留上一個1的位置即可 https://blog.csdn.net/fuxuemingzhu/article/details/81079495
104. Maximum Depth of Binary Tree Easy 二叉樹的高度,可以用DFS和BFS https://blog.csdn.net/fuxuemingzhu/article/details/48490829
136. Single Number Easy 所有的數字出現了兩次,其中一個只出現了一次。找出這個數字的方法可以使用字典統計或者異或運算 https://blog.csdn.net/fuxuemingzhu/article/details/54173334
496. Next Greater Element I Easy 找出某個數字右邊比他大的數字,直接遍歷查詢就好了 https://blog.csdn.net/fuxuemingzhu/article/details/79080337
637. Average of Levels in Binary Tree Easy 求每層的二叉樹的均值,可以使用BFS和DFS https://blog.csdn.net/fuxuemingzhu/article/details/79088554
693. Binary Number with Alternating Bits Easy 判斷數字的二進位制表示是不是01交錯的。直接遍歷判斷,或者位運算。 https://blog.csdn.net/fuxuemingzhu/article/details/79089937
762. Prime Number of Set Bits in Binary Representation Easy 判斷二進位制數字的1的個數是不是質數 https://blog.csdn.net/fuxuemingzhu/article/details/79089092
917. Reverse Only Letters Easy 只翻轉字母其餘字元不動,可以使用棧、雙指標 https://blog.csdn.net/fuxuemingzhu/article/details/82956271
292. Nim Game Easy 判斷輸入數字是不是4的倍數即可 https://blog.csdn.net/fuxuemingzhu/article/details/51284421
824. Goat Latin Easy 字串處理,簡單 https://blog.csdn.net/fuxuemingzhu/article/details/80471925
892. Surface Area of 3D Shapes Easy 統計立方體個數,減去相交面積 https://blog.csdn.net/fuxuemingzhu/article/details/82083893
784. Letter Case Permutation Easy 經典回溯法,把字元的大小寫分別拼接到字串尾部 https://blog.csdn.net/fuxuemingzhu/article/details/79360330
258. Add Digits Easy 兩重迴圈,一直對每位數字求和直到剩餘個位數 https://blog.csdn.net/fuxuemingzhu/article/details/49161129
283. Move Zeroes Easy 使用一個指標指向第一個為0的位置,然後遍歷不是0的位置進行交換 https://blog.csdn.net/fuxuemingzhu/article/details/51284981
748. Shortest Completing Word Easy 找出符合某個模式的字串,直接處理就好了 https://blog.csdn.net/fuxuemingzhu/article/details/79432228
690. Employee Importance Easy dfs https://blog.csdn.net/fuxuemingzhu/article/details/79091343
389. Find the Difference Easy 找多出來的字元,可以使用字典,也可以使用異或 https://blog.csdn.net/fuxuemingzhu/article/details/54174443
520. Detect Capital Easy 統計大寫字元的個數,判斷是不是在首位 https://blog.csdn.net/fuxuemingzhu/article/details/68957658
448. Find All Numbers Disappeared in an Array Easy 用set去重,找出沒有出現的數字即可 https://blog.csdn.net/fuxuemingzhu/article/details/53981307
696. Count Binary Substrings Easy 先找出連續的0,1個數,然後進行交錯求最小值,在求和 https://blog.csdn.net/fuxuemingzhu/article/details/79183556
454. 4Sum II Easy 4sum,先確定兩個數字,然後看剩餘兩個數字的和是否出現過 https://blog.csdn.net/fuxuemingzhu/article/details/79473739
788. Rotated Digits Easy 字典儲存翻轉後的數字,判斷是否相等即可。 https://blog.csdn.net/fuxuemingzhu/article/details/79378135
653. Two Sum IV - Input is a BST Easy BFS或者DFS,在遍歷的過程中進行破案噸 https://blog.csdn.net/fuxuemingzhu/article/details/79120732
371. Sum of Two Integers Easy 位運算 https://blog.csdn.net/fuxuemingzhu/article/details/79379939
349. Intersection of Two Arrays Easy 用兩個set求交集,然後轉成List即可 https://blog.csdn.net/fuxuemingzhu/article/details/54236183
606. Construct String from Binary Tree Easy 先序遍歷,可以省略右子樹,所以需要做一個節點是否存在的判斷 https://blog.csdn.net/fuxuemingzhu/article/details/79121550
206. Reverse Linked List Easy 翻轉單鏈表,可以使用遞迴和迭代 https://blog.csdn.net/fuxuemingzhu/article/details/51290121
169. Majority Element Easy Moore投票法,或者字典統計次數 https://blog.csdn.net/fuxuemingzhu/article/details/51288749
171. Excel Sheet Column Number Easy 26進位制,沒有難度 https://blog.csdn.net/fuxuemingzhu/article/details/51286467
13. Roman to Integer Easy 使用字典儲存對映,遍歷求值就好了。 https://blog.csdn.net/fuxuemingzhu/article/details/48208995
937. Reorder Log Files Easy 分割排序,再拼接 https://blog.csdn.net/fuxuemingzhu/article/details/83961188
121. Best Time to Buy and Sell Stock Easy 一次遍歷,如果後一天比前一天大就買了賣 https://blog.csdn.net/fuxuemingzhu/article/details/51291151
242. Valid Anagram Easy 判斷字串是否是同構的,直接統計詞頻或者排序 https://blog.csdn.net/fuxuemingzhu/article/details/51286195
860. Lemonade Change Easy 貪心演算法,找零錢先找大的面額,如果不夠再用小的面額 https://blog.csdn.net/fuxuemingzhu/article/details/80913955
217. Contains Duplicate Easy 判斷陣列是否有重複,可以統計詞頻,判斷set長度是否相等,排序等方法 https://blog.csdn.net/fuxuemingzhu/article/details/51289768
427. Construct Quad Tree Easy 建立四叉樹,使用遞迴,判斷4個葉子全部是0或者1 https://blog.csdn.net/fuxuemingzhu/article/details/81836838
706. Design HashMap Easy 設計一個字典,直接開個很大的陣列即可,記憶體放得下 https://blog.csdn.net/fuxuemingzhu/article/details/81017297
538. Convert BST to Greater Tree Easy 把每個節點變成比它大的節點的值的和,採用逆中序遍歷。 https://blog.csdn.net/fuxuemingzhu/article/details/79132336
100. Same Tree Easy 判斷兩棵數是否相等,直接遞迴 https://blog.csdn.net/fuxuemingzhu/article/details/51285076
530. Minimum Absolute Difference in BST Easy 中序遍歷,儲存前一個節點,當前節點的值減去前一個節點的值 https://blog.csdn.net/fuxuemingzhu/article/details/69666671
783. Minimum Distance Between BST Nodes Easy 和上題完全一樣 https://blog.csdn.net/fuxuemingzhu/article/details/79402127
383. Ransom Note Easy 使用字典統計每個字元出現的次數,前者小於後者即可 https://blog.csdn.net/fuxuemingzhu/article/details/54178342
796. Rotate String Easy 字串切片 https://blog.csdn.net/fuxuemingzhu/article/details/79521194
717. 1-bit and 2-bit Characters Easy 單次遍歷,判斷前面滿足的條件下,最後一位是0即可。 https://blog.csdn.net/fuxuemingzhu/article/details/79130681
453. Minimum Moves to Equal Array Elements Easy 把n-1個數字加1,相等於把最大值-1.求和-n*最小值 https://blog.csdn.net/fuxuemingzhu/article/details/54177981
733. Flood Fill Easy 對相同顏色進行染色,可以使用DFS和BFS. https://blog.csdn.net/fuxuemingzhu/article/details/79401716
404. Sum of Left Leaves Easy 求所有左葉子的和,要判斷是不是在左邊,判斷是不是葉子,然後加到結果中 https://blog.csdn.net/fuxuemingzhu/article/details/54178595
447. Number of Boomerangs Easy 統計迴旋鏢的個數,不能暴力解決,需要使用排列組合公式n*(n-1) https://blog.csdn.net/fuxuemingzhu/article/details/54379349
598. Range Addition II Easy 求佇列的最小值即可 https://blog.csdn.net/fuxuemingzhu/article/details/79398272
492. Construct the Rectangle Easy 從算術平方根開始找約數即可 https://blog.csdn.net/fuxuemingzhu/article/details/68957959
167. Two Sum II - Input array is sorted Easy 前後指標同時向中間走,找到target之後停止 https://blog.csdn.net/fuxuemingzhu/article/details/70232518
387. First Unique Character in a String Easy 首先做個字元出現次數的統計,然後再次遍歷,找出只出現了一次的第一個字元。 https://blog.csdn.net/fuxuemingzhu/article/details/84139374
697. Degree of an Array Easy 求最大的出現次數的所有數字,其最左右出現的位置差的最小值 https://blog.csdn.net/fuxuemingzhu/article/details/79146067
455. Assign Cookies Easy 貪心演算法,儘可能給小孩滿足其慾望的餅乾 https://blog.csdn.net/fuxuemingzhu/article/details/54177627
108. Convert Sorted Array to Binary Search Tree Easy 構建BST,使用中間數進行分割,用遞迴 https://blog.csdn.net/fuxuemingzhu/article/details/70665213
506. Relative Ranks Easy 相對排名,可以使用堆或者排序或者argsort https://blog.csdn.net/fuxuemingzhu/article/details/70173434
661. Image Smoother Easy 直接暴力求平均即可 https://blog.csdn.net/fuxuemingzhu/article/details/79156499
409. Longest Palindrome Easy 統計出現次數的奇偶就可以 https://blog.csdn.net/fuxuemingzhu/article/details/54236594
599. Minimum Index Sum of Two Lists Easy 儲存出現的索引和與元素的對應,使用堆儲存最小的就行 https://blog.csdn.net/fuxuemingzhu/article/details/79138621
268. Missing Number Easy 理論和-當前和 https://blog.csdn.net/fuxuemingzhu/article/details/70332471
563. Binary Tree Tilt Easy 後序遍歷函式返回的是左右子樹的差,在裡面用變數求和 https://blog.csdn.net/fuxuemingzhu/article/details/71440281
830. Positions of Large Groups Easy 找到長度大於3的連續字元,需要判斷結束!! https://blog.csdn.net/fuxuemingzhu/article/details/80472242
350. Intersection of Two Arrays II Easy 可以排序,也可以使用字典統計次數 https://blog.csdn.net/fuxuemingzhu/article/details/54341965
543. Diameter of Binary Tree Easy 遞迴求樹的深度,同時求左右兩個深度的和的最大值 https://blog.csdn.net/fuxuemingzhu/article/details/70338312
551. Student Attendance Record I Easy 統計A的個數,並且判斷連續L的個數 https://blog.csdn.net/fuxuemingzhu/article/details/70337973
121. Best Time to Buy and Sell Stock Easy 儲存當前的最小值以及最大收益即可 https://blog.csdn.net/fuxuemingzhu/article/details/51291151
628. Maximum Product of Three Numbers Easy 找出三個數最大的乘積 https://blog.csdn.net/fuxuemingzhu/article/details/79169635
401. Binary Watch Easy 使用combinations函式 https://blog.csdn.net/fuxuemingzhu/article/details/54344098
746. Min Cost Climbing Stairs Easy 動態規劃 https://blog.csdn.net/fuxuemingzhu/article/details/79188612
925. Long Pressed Name Easy 使用雙指標,統計連續字元出現的次數 https://blog.csdn.net/fuxuemingzhu/article/details/83245395
541. Reverse String II Easy Python的切片翻轉 https://blog.csdn.net/fuxuemingzhu/article/details/70141909
705. Design HashSet Easy 直接開陣列就行 https://blog.csdn.net/fuxuemingzhu/article/details/81016992
107. Binary Tree Level Order Traversal II Easy DFS和BFS都可以 https://blog.csdn.net/fuxuemingzhu/article/details/49108449
504. Base 7 Easy 轉成7進位制 https://blog.csdn.net/fuxuemingzhu/article/details/70194688
115. Distinct Subsequences Easy 動規,判斷當前字元是否相等 https://blog.csdn.net/fuxuemingzhu/article/details/84228383
21. Merge Two Sorted Lists Easy 可以使用遞迴或者迭代 https://blog.csdn.net/fuxuemingzhu/article/details/51291406
458. Poor Pigs Easy 類似撥號鍵盤,多維空間求解 https://blog.csdn.net/fuxuemingzhu/article/details/81079261
257. Binary Tree Paths Easy 列印二叉樹的路徑,使用遞迴和迭代 https://blog.csdn.net/fuxuemingzhu/article/details/71249429
844. Backspace String Compare Easy 字串可以退格,使用棧輕鬆解決 https://blog.csdn.net/fuxuemingzhu/article/details/80643408
202. Happy Number Easy 遞迴和迭代兩種做法 https://blog.csdn.net/fuxuemingzhu/article/details/49180507
674. Longest Continuous Increasing Subsequence Easy 簡單的動態規劃 https://blog.csdn.net/fuxuemingzhu/article/details/79220527
744. Find Smallest Letter Greater Than Target Easy 線性掃描或者二分 https://blog.csdn.net/fuxuemingzhu/article/details/79137225
118. Pascal’s Triangle Easy 提前構造出來,然後處理每行即可 https://blog.csdn.net/fuxuemingzhu/article/details/51346488
671. Second Minimum Node In a Binary Tree Easy 遞迴的時候找第二小值 https://blog.csdn.net/fuxuemingzhu/article/details/79222455
720. Longest Word in Dictionary Easy 先排序,再找字首是否存在。 https://blog.csdn.net/fuxuemingzhu/article/details/79123277
27. Remove Element Easy 使用雙指標或者標記指標使得前面都是滿足要求的,後面都不滿足 https://blog.csdn.net/fuxuemingzhu/article/details/51303161
70. Climbing Stairs Easy 動態規劃 https://blog.csdn.net/fuxuemingzhu/article/details/51290778
415. Add Strings Easy 直接模擬大整數加法,需要注意進位問題 https://blog.csdn.net/fuxuemingzhu/article/details/54380737
235. Lowest Common Ancestor of a Binary Search Tree Easy BST找公共祖先,使用遞迴很簡單 https://blog.csdn.net/fuxuemingzhu/article/details/51290289
594. Longest Harmonious Subsequence Easy 統計相鄰的數字是否都存在即可 https://blog.csdn.net/fuxuemingzhu/article/details/79233752
101. Symmetric Tree Easy 可以使用BFS和DFS兩種方法 https://blog.csdn.net/fuxuemingzhu/article/details/51345707
53. Maximum Subarray Easy 動態規劃找子陣列最大和 https://blog.csdn.net/fuxuemingzhu/article/details/71101802
819. Most Common Word Easy 正則+統計 https://blog.csdn.net/fuxuemingzhu/article/details/80472079
231. Power of Two Easy 判斷二進位制是不是隻有1個1即可 https://blog.csdn.net/fuxuemingzhu/article/details/51290981
405. Convert a Number to Hexadecimal Easy 轉成16進位制,難點在於負數的處理:加上1<<32 https://blog.csdn.net/fuxuemingzhu/article/details/54426643
83. Remove Duplicates from Sorted List Easy 遞迴和迴圈 https://blog.csdn.net/fuxuemingzhu/article/details/51290506
326. Power of Three Easy 迴圈和迭代 https://blog.csdn.net/fuxuemingzhu/article/details/51290895
191. Number of 1 Bits Easy 使用位移統計二進位制個數 https://blog.csdn.net/fuxuemingzhu/article/details/51290376
437. Path Sum III Easy 找路徑的個數,使用DFS*2或者BFS+DFS https://blog.csdn.net/fuxuemingzhu/article/details/71097135
704. Binary Search Easy 二分的模板 https://blog.csdn.net/fuxuemingzhu/article/details/81017415
119. Pascal’s Triangle II Easy 原地翻轉可以用倒序遍歷 https://blog.csdn.net/fuxuemingzhu/article/details/51348629
232. Implement Queue using Stacks Easy 兩個棧實現一個佇列 https://blog.csdn.net/fuxuemingzhu/article/details/51345762
572. Subtree of Another Tree Easy DFS*2或DFS+BSF https://blog.csdn.net/fuxuemingzhu/article/details/71440802
198. House Robber Easy 簡單dp,當前房間偷和不偷兩種狀態 https://blog.csdn.net/fuxuemingzhu/article/details/51291936
703. Kth Largest Element in a Stream Easy 使用小根堆維護k個值,則第一個元素就是第k大元素 https://blog.csdn.net/fuxuemingzhu/article/details/81027116
345. Reverse Vowels of a String Easy 使用棧進行翻轉,或者使用雙指標 https://blog.csdn.net/fuxuemingzhu/article/details/51291677
66. Plus One Easy 使用carry表示進位 https://blog.csdn.net/fuxuemingzhu/article/details/51346096
263. Ugly Number Easy 除去2,3,5因子即可 https://blog.csdn.net/fuxuemingzhu/article/details/49183961
35. Search Insert Position Easy 二分查詢 https://blog.csdn.net/fuxuemingzhu/article/details/70738108
645. Set Mismatch Easy 使用統計次數或者直接求和計算 https://blog.csdn.net/fuxuemingzhu/article/details/79247916
747. Largest Number At Least Twice of Others Easy 找出最大值,然後彈掉,再找次大值即可。 https://blog.csdn.net/fuxuemingzhu/article/details/79188909
342. Power of Four Easy 遞迴和迭代 https://blog.csdn.net/fuxuemingzhu/article/details/51291091
724. Find Pivot Index Easy 先求和,在遍歷求前半部分的和,找出左邊等於右邊 https://blog.csdn.net/fuxuemingzhu/article/details/79248308
9. Palindrome Number Easy 可以先翻轉成整數,然後判斷和原來的是否相等 https://blog.csdn.net/fuxuemingzhu/article/details/71334663
482. License Key Formatting Easy 計算第一個分割的長度,後面都是等長的了 https://blog.csdn.net/fuxuemingzhu/article/details/79234075
1. Two Sum Easy 儲存已經出現過的數字的索引,當下次遍歷的時候遇到了滿足要求的結果,那麼既是停止 https://blog.csdn.net/fuxuemingzhu/article/details/72465759
459. Repeated Substring Pattern Easy 判斷每個子串重複多次能不能組成原來的串即可 https://blog.csdn.net/fuxuemingzhu/article/details/54564801
849. Maximize Distance to Closest Person Easy 從前向後以及從後向前遍歷兩次,取最近距離 https://blog.csdn.net/fuxuemingzhu/article/details/80643250
38. Count and Say Easy 統計字元連續出現的次數,並說出來,需要注意最後的一個字元也要新增上去 https://blog.csdn.net/fuxuemingzhu/article/details/71618640
80. Remove Duplicates from Sorted Array II Easy 快指標移動判斷和慢指標是否相等,如果不等就換到前面來 https://blog.csdn.net/fuxuemingzhu/article/details/82829709
643. Maximum Average Subarray I Easy 一定注意是長度為k的滑動視窗,注意下標 https://blog.csdn.net/fuxuemingzhu/article/details/79248629
501. Find Mode in Binary Search Tree Easy 如果使用附加空間,可以使用字典儲存次數;否則需要遍歷兩次,判斷出現次數。 https://blog.csdn.net/fuxuemingzhu/article/details/71124600
374. Guess Number Higher or Lower Easy 使用二分查詢 https://blog.csdn.net/fuxuemingzhu/article/details/71516105
743. Network Delay Time Easy dijkstra演算法 https://leetcode.com/problems/network-delay-time/description/
558. Quad Tree Intersection Easy 遞迴構造 https://blog.csdn.net/fuxuemingzhu/article/details/82356008
172. Factorial Trailing Zeroes Easy 數有多少個5就行了 https://blog.csdn.net/fuxuemingzhu/article/details/51347044
441. Arranging Coins Easy 二分查詢滿足條件的層數即可 https://blog.csdn.net/fuxuemingzhu/article/details/71330733
225. Implement Stack using Queues Easy 使用一個佇列就能實現棧,每次Push的時候,把佇列裡的所有元素彈出再放進來就好了。 https://blog.csdn.net/fuxuemingzhu/article/details/72598111
67. Add Binary Easy 使用進位進行模擬 ddhttps://blog.csdn.net/fuxuemingzhu/article/details/77341154v
434. Number of Segments in a String Easy string.split()預設就是按照多個空格分割 https://blog.csdn.net/fuxuemingzhu/article/details/71194298
112. Path Sum Easy 遞迴和迭代都能滿足 https://blog.csdn.net/fuxuemingzhu/article/details/71715810
205. Isomorphic Strings Easy 分別看s到t的對映和t到s的對映是不是一一對映的 https://blog.csdn.net/fuxuemingzhu/article/details/72127108
443. String Compression Easy 使用Pos變數維護應該放到哪個位置,然後一次遍歷統計次數就好了 https://blog.csdn.net/fuxuemingzhu/article/details/79183289
303. Range Sum Query - Immutable Easy 儲存每個位置的累積和 https://blog.csdn.net/fuxuemingzhu/article/details/79253036
438. Find All Anagrams in a String Easy 滑動視窗,儲存等長的子字串中包含的字元數是否和另外一個相等 https://blog.csdn.net/fuxuemingzhu/article/details/79184109
20. Valid Parentheses Easy 使用棧判斷括號是否合法 https://blog.csdn.net/fuxuemingzhu/article/details/72366868
840. Magic Squares In Grid Easy 暴力判斷每個9*9的格子是不是滿足題意的河圖 https://blog.csdn.net/fuxuemingzhu/article/details/80473253
141. Linked List Cycle Easy 走兩步走一步,看是否重合 https://blog.csdn.net/fuxuemingzhu/article/details/51297249
203. Remove Linked List Elements Easy 遞迴解法不好想,但是程式碼很簡單 https://blog.csdn.net/fuxuemingzhu/article/details/77340945
234. Palindrome Linked List Easy 利用一個數組儲存所有的數字,然後判斷陣列是不是迴文的。 https://blog.csdn.net/fuxuemingzhu/article/details/72597942
111. Minimum Depth of Binary Tree Easy DFS/BFS,其實DFS更難 https://blog.csdn.net/fuxuemingzhu/article/details/48519035
290. Word Pattern Easy 一一對映 https://blog.csdn.net/fuxuemingzhu/article/details/72528424
155. Min Stack Easy 使用輔助棧儲存最小值 https://blog.csdn.net/fuxuemingzhu/article/details/79253237
219. Contains Duplicate II Easy 使用字典儲存出現的位置,當新的元素到來的時候,更新字典 https://blog.csdn.net/fuxuemingzhu/article/details/77387169
941. Valid Mountain Array Easy 兩個while就可以了 https://blog.csdn.net/fuxuemingzhu/article/details/84206380
88. Merge Sorted Array Easy 從後向前進行遍歷,每次找到大的往後移動 https://blog.csdn.net/fuxuemingzhu/article/details/77444695
914. X of a Kind in a Deck of Cards Easy 需要進行一個遍歷,找到是否存在這個分組大小 https://blog.csdn.net/fuxuemingzhu/article/details/82914279
680. Valid Palindrome II Easy 需要用到雙指標,先找到第一個不相等的位置,然後去除左邊或者右邊,判斷是否是迴文 https://blog.csdn.net/fuxuemingzhu/article/details/79252779
687. Longest Univalue Path Easy 定義的DFS是對過root的單臂進行迴圈,但是更新的結果是雙臂,有點意思 https://blog.csdn.net/fuxuemingzhu/article/details/79248926
14. Longest Common Prefix Easy 遍歷最短的子串的每一位,看所有字串在這一位上是不是相等的 https://blog.csdn.net/fuxuemingzhu/article/details/77561186
686. Repeated String Match Easy 重複NB/NA + 3次,看b是不是在a裡 https://blog.csdn.net/fuxuemingzhu/article/details/79574835
122.Best Time to Buy and Sell Stock II Easy 只要每天的比前面一天高,那麼就買上並且賣掉即可 https://blog.csdn.net/fuxuemingzhu/article/details/70258549
28. Implement strStr() Easy 迴圈加切片 https://blog.csdn.net/fuxuemingzhu/article/details/79254558
475. Heaters Easy 找出最臨近的距離 https://blog.csdn.net/fuxuemingzhu/article/details/79254295
754. Reach a Number Easy 數學題,非常不喜歡 https://blog.csdn.net/fuxuemingzhu/article/details/84556932
400. Nth Digit Easy 數學計算第多少位 https://blog.csdn.net/fuxuemingzhu/article/details/84559975
69. Sqrt(x) Easy 二分查詢或者牛頓法 https://blog.csdn.net/fuxuemingzhu/article/details/79254648
581. Shortest Unsorted Continuous Subarray Easy 先排序,然後比較不等的位置 https://blog.csdn.net/fuxuemingzhu/article/details/79254454
190. Reverse Bits Easy 翻轉二進位制再轉成整數 https://blog.csdn.net/fuxuemingzhu/article/details/79254344
125. Valid Palindrome Easy 過濾掉不是字母的字元,然後判斷是不是迴文即可 https://blog.csdn.net/fuxuemingzhu/article/details/79252936
874. Walking Robot Simulation Easy 模擬整個過程即可 https://blog.csdn.net/fuxuemingzhu/article/details/82356556
532. K-diff Pairs in an Array Easy 找絕對值出現等於k的次數,需要對k進行判斷 https://blog.csdn.net/fuxuemingzhu/article/details/79255633
168. Excel Sheet Column Title Easy 需要對26取餘,並且做個判斷,因為0\26對26取餘的結果是一樣的 https://blog.csdn.net/fuxuemingzhu/article/details/51286857
189. Rotate Array Easy 可以使用額外陣列,也可使用遞迴原地翻轉 https://blog.csdn.net/fuxuemingzhu/article/details/79258753
665. Non-decreasing Array Easy 找到變小的位置,然後和再前面的數字進行判斷,看是應該修改當前的還是前面的 https://blog.csdn.net/fuxuemingzhu/article/details/79264475
707. Design Linked List Easy 自己實現連結串列,挺複雜的。可以使用list進行模擬,方便很多。 https://blog.csdn.net/fuxuemingzhu/article/details/81026066
938. Range Sum of BST Medium 需要根據根節點的值進行判斷,郵編和左邊需不需要繼續尋找 https://blog.csdn.net/fuxuemingzhu/article/details/83961263
807. Max Increase to Keep City Skyline Medium 分別找出行和咧的最大值,把每個位置增長到行列最大值的最小值 https://blog.csdn.net/fuxuemingzhu/article/details/79820383
535. Encode and Decode TinyURL Medium 使用字典完成對映 https://blog.csdn.net/fuxuemingzhu
654. Maximum Binary Tree Medium 找到最大值,然後陣列切片 https://blog.csdn.net/fuxuemingzhu/article/details/79265180
701. Insert into a Binary Search Tree