最近的更新在github上,訪問我的github倉庫:https://github.com/JackKuo666/leetcode_notes
目錄如下:
# | Title | Solution | Basic idea (One line) | Note | Difficulty |
---|---|---|---|---|---|
1 | 兩數之和 | Python | 1. Hash O(n) and O(n) space. 2. 暴力遍歷法 O(n^2) and O(1). 3.sort+雙指針 >O(n) and O(n) |
沒排序的輸入,最好使用Hashmap法 | Easy |
2 | 兩個鏈表數字之和 | Python | 1.分佈遍歷兩個鏈表,轉成數字,相加,然後轉成鏈表 O(n) and O(n) | Medium | |
3 | 最長無重複子字符串 | Python | 1.哈希表+單指針 O(n) and O(1) | Medium | |
4 | 兩個排序列表的中位數 | Python | 1.常規解法:合併兩個列表+sort() O((m+n)log(m+n)) 2.二分查找法 O(log(m+n)) |
二分查找法解析見這裏 | Hard |
5 | 最長迴文子串 | Python | 1.DP: O(n^2) and O(n^2) 2.manacher算法 O(n) and O(n) |
解析請看這裏 | Medium |
6 | Z字形變換解析 | Python | 1.創建一個list保存,然後打印出來 O(n) and O(n) | 解析見我的博客 | Medium |
7 | 反向整數 | Python | 1.str法 24ms 2.除法 24ms 3.str法+abs 36ms |
Easy | |
8 | 字符串轉整形 | Python | 1.判斷法 O(n) and O(1) | Medium | |
9 | 迴文數字 | Python | 1.str法 76ms | Easy | |
10 | 正則表達式匹配 | Python | 1.內置函數 64ms 2.遞歸 TLE 3.DP O(mn) and O(mn) |
解析見我的博客 | Hard |
11 | 大多數水的容器 | Python | 1.雙指針 O(n^2) and O(1) | Medium | |
12 | 整數轉羅馬數 | Python | 1.字典法 | 注意:4:不是 IIII 而是 IV | Medium |
13 | 羅馬數轉整數 | Python | 1.字典法 | IV:4 -> IIII IX:9 -> VIIII 就可以方便的使用字典法 | Easy |
14 | 最長的共同前綴 | Python | 1.zip(*strs)+set O(n) and O(1) | 記得zip(*strs)用法 | Easy |
15 | 三數之和 | Python | 1.三指針 O(n^2) and O(1) | Since sorting is done in O(nlogn),which is less than O(n^2) you can ignore it. Of course only because the total would be the sum O(nlogn + n^2) |
Medium |
16 | 三數之和最近 | Python | 1.三指針 O(n^2) and O(1) | Medium | |
17 | 電話號碼的字母組合 | Python | 1.數組法 O(n4^(n+1)) and O(n) 2.回溯法 > O(n4^(n+1)) and O(n) |
Medium | |
18 | 四數之和 | Python | 1.遞歸到2sum O(n^3) and O(n) | 本方法是Nsum遞歸到2sum的通用解法 解析見這裏 |
Medium |
19 | 從列表末尾刪除第N個節點 | Python | 1.數組遍歷法 O(n^2) and O(n) 2.遞歸法 O(n) and O(1) 推薦 3.快慢指針法 O(n^2) and O(1) 標準解法 |
基礎解法是法1;遞歸法來自這裏,很巧妙;標準解法是法3 | Medium |
之前隨便刷的目錄:
哈希表:1.two-sum: https://leetcode.com/problems/two-sum/description/
【leetcode筆記】Python實現9.迴文數
【leetcode筆記】Python實現18.四數之和
【leetcode筆記】Python實現19. 刪除鏈表的倒數第N個節點
【leetcode筆記】Python實現:31.下一個排列
二分(題號:69):https://leetcode.com/problems/sqrtx/description/
荷蘭國旗問題:75. Sort Colors
https://leetcode.com/problems/sort-colors/description/
雙指針:167. Two Sum II - Input array is sorted
https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/description/
排序:
快速選擇、堆排序:215. Kth Largest Element in an Array
https://leetcode.com/problems/kth-largest-element-in-an-array/description/
【leetcode筆記】Python實現215.Kth Largest Element in an Array
桶排序:347. Top K Frequent Elements
https://leetcode.com/problems/top-k-frequent-elements/description/
【leetcode筆記】Python實現347. Top K Frequent Elements
貪心:455. Assign Cookies
https://leetcode.com/problems/assign-cookies/description/
分治(題號:241):https://leetcode.com/problems/different-ways-to-add-parentheses/description/
【leetcode筆記】Python實現 LeetCode 241. Different Ways to Add Parentheses
鏈表(題號:160):https://leetcode.com/problems/intersection-of-two-linked-lists/description/
【leetcode筆記】Python實現 LeetCode 160. Intersection of Two Linked Lists
字符串(題號:242):https://leetcode.com/problems/valid-anagram/description/
棧和隊列(題號:232):https://leetcode.com/problems/implement-queue-using-stacks/description/
【leetcode筆記】Python實現 232. Implement Queue using Stacks
字符串(409):https://leetcode.com/problems/longest-palindrome/description/
數組和矩陣(378):https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/description/
位運算(260):https://leetcode.com/problems/single-number-iii/description/
位運算(136):https://leetcode.com/problems/single-number/description/
數學進制轉換(504):https://leetcode.com/problems/base-7/description/
相遇問題(462):https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/description/
多數投票問題(169):https://leetcode.com/problems/majority-element/description/
樹:
遞歸(110):https://leetcode.com/problems/balanced-binary-tree/description/
層次遍歷(513):https://leetcode.com/problems/find-bottom-left-tree-value/description/
前中後序遍歷(144):https://leetcode.com/problems/binary-tree-preorder-traversal/description/
BST(230):https://leetcode.com/problems/kth-smallest-element-in-a-bst/description/
Trie(208):https://leetcode.com/problems/implement-trie-prefix-tree/description/
https://blog.csdn.net/weixin_37251044/article/details/88822071
圖:
二分圖(785):https://leetcode.com/problems/is-graph-bipartite/description/
【leetcode筆記】Python實現 785. Is Graph Bipartite?
拓撲排序(207):https://leetcode.com/problems/course-schedule/description/
【leetcode筆記】Python實現 207. Course Schedule
並查集(684):https://leetcode.com/problems/redundant-connection/description/
搜索:
BFS(279):https://leetcode.com/problems/perfect-squares/description/
【leetcode筆記】Python實現 279. Perfect Squares
DFS(695):https://leetcode.com/problems/max-area-of-island/description/
【leetcode筆記】Python實現 695. Max Area of Island
Backtracking(17):https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/
【leetcode筆記】Python實現 17. Letter Combinations of a Phone Number
動態規劃:
斐波那契數列(70):https://leetcode.com/problems/climbing-stairs/description/
矩陣路徑(64):https://leetcode.com/problems/minimum-path-sum/description/
【leetcode筆記】Python實現 64. Minimum Path Sum
數組區間(303):https://leetcode.com/problems/range-sum-query-immutable/description/
分割整數(343):https://leetcode.com/problems/integer-break/description/
【leetcode筆記】Python實現 343. Integer Break
最長遞增子序列(300):https://leetcode.com/problems/longest-increasing-subsequence/description/
【leetcode筆記】Python實現 300. Longest Increasing Subsequence
0-1 揹包(416):https://leetcode.com/problems/partition-equal-subset-sum/description/
【leetcode筆記】Python實現 416. Partition Equal Subset Sum
股票交易(309):https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/description/
【leetcode筆記】Python實現 714. Best Time to Buy and Sell Stock with Transaction Fee
【leetcode筆記】Python實現 309. Best Time to Buy and Sell Stock with Cooldown
字符串編輯(583):https://leetcode.com/problems/delete-operation-for-two-strings/description/