leetcode是一個很有名的線上OJ,今年新增了Database和shell模組,難度分為easy、medium和hard三檔,非常適合新手練習資料結構和演算法,支援多種語言,但是目前只支援英文刷題。
已經在leetcode上斷斷續續刷了一年題了,但是之前一直沒有把解題思路記錄下來,很多題已經忘記了,再次遇到同型別的題又不知道從何下手,現更新此部落格,記錄下刷題的思路,加深了對知識點的理解。程式語言使用Swift。
首先宣告,我也只是個演算法菜鳥,為加強演算法能力在leetcode上刷題,如果解題思路有問題,或對演算法有可優化的地方,才疏學淺,歡迎指出。 在此附上github 傳送門,倉庫內有之前的刷題記錄,均已通過leetcode校驗,由於時間比較長,leetcode上可能會有所調整,有任何問題,歡迎反饋。
Stack
84. Largest Rectangle in Histogram
199. Binary Tree Right Side View
Greedy
738. Monotone Increasing Digits
659. Split Array into Consecutive Subsequences
BFS
DFS
114. Flatten Binary Tree to Linked List
98. Validate Binary Search Tree
797. All Paths From Source to Target
String
5. Longest Palindromic Substring
821. Shortest Distance to a Character
Tree
653. Two Sum IV - Input is a BST
669. Trim a Binary Search Tree
637. Average of Levels in Binary Tree
671. Second Minimum Node In a Binary Tree
606. Construct String from Binary Tree
Binary Tree Traversal(preoder、inorder、level、zigzal level)
662. Maximum Width of Binary Tree
230. Kth Smallest Element in a BST
783. Minimum Distance Between BST Nodes
DP
Unique Binary Search Trees I, II
718. Maximum Length of Repeated Subarray
583. Delete Operation for Two Strings
698. Partition to K Equal Sum Subsets
823. Binary Trees With Factors
Hash Table
Array
747. Largest Number At Least Twice of Others
795. Number of Subarrays with Bounded Maximum
807. Max Increase to Keep City Skyline
825. Friends Of Appropriate Ages
826. Most Profit Assigning Work
String
522. Longest Uncommon Subsequence II
424. Longest Repeating Character Replacement
830. Positions of Large Groups
831. Masking Personal Information
820. Short Encoding of Words 824. Goat Latin 833. Find And Replace in String
List
725 Split Linked List in Parts
Bit Manipulation
Math
592. Fraction Addition and Subtraction