leetcode是一个很有名的在线OJ,今年新增了Database和shell模块,难度分为easy、medium和hard三档,非常适合新手练习数据结构和算法,支持多种语言,但是目前只支持英文刷题。
已经在leetcode上断断续续刷了一年题了,但是之前一直没有把解题思路记录下来,很多题已经忘记了,再次遇到同类型的题又不知道从何下手,现更新此博客,记录下刷题的思路,加深了对知识点的理解。编程语言使用Swift。
首先声明,我也只是个算法菜鸟,为加强算法能力在leetcode上刷题,如果解题思路有问题,或对算法有可优化的地方,才疏学浅,欢迎指出。 在此附上github 传送门,仓库内有之前的刷题记录,均已通过leetcode校验,由于时间比较长,leetcode上可能会有所调整,有任何问题,欢迎反馈。
Stack
739. Daily Temperatures
84. Largest Rectangle in Histogram
385. Mini Parser
199. Binary Tree Right Side View
Greedy
738. Monotone Increasing Digits
659. Split Array into Consecutive Subsequences
649. Dota2 Senate
BFS
130. Surrounded Regions
752. Open the Lock
DFS
733. Flood Fill
337. House Robber III
129. Sum Root to Leaf Numbers
114. Flatten Binary Tree to Linked List
98. Validate Binary Search Tree
547 Friend Circles
638. Shopping Offers
797. All Paths From Source to Target
String
5. Longest Palindromic Substring
804. Unique Morse Code Words
821. Shortest Distance to a Character
819. Most Common Word
Tree
654. Maximum Binary Tree
653. Two Sum IV - Input is a BST
669. Trim a Binary Search Tree
637. Average of Levels in Binary Tree
687. Longest Univalue Path
671. Second Minimum Node In a Binary Tree
606. Construct String from Binary Tree
450. Delete Node in a BST
Binary Tree Traversal(preoder、inorder、level、zigzal level)
Construct Binary Tree
662. Maximum Width of Binary Tree
623. Add One Row to Tree
652. Find Duplicate Subtrees
655. Print Binary Tree
230. Kth Smallest Element in a BST
783. Minimum Distance Between BST Nodes
814. Binary Tree Pruning
DP
740. Delete and Earn
House Robber I, II
Unique Binary Search Trees I, II
718. Maximum Length of Repeated Subarray
746. Min Cost Climbing Stairs
583. Delete Operation for Two Strings
698. Partition to K Equal Sum Subsets
486. Predict the Winner
823. Binary Trees With Factors
Hash Table
748. Shortest Completing Word
771. Jewels and Stones
781. Rabbits in Forest
811. Subdomain Visit Count
Array
747. Largest Number At Least Twice of Others
Max Chunks To Make Sorted
766. Toeplitz Matrix
795. Number of Subarrays with Bounded Maximum
807. Max Increase to Keep City Skyline
825. Friends Of Appropriate Ages
826. Most Profit Assigning Work
822. Card Flipping Game
832. Flipping an Image
String
556. Next Greater Element III
522. Longest Uncommon Subsequence II
809. Expressive Words
791. Custom Sort String
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
817. Linked List Components
Bit Manipulation
Hamming Distance
Math
592. Fraction Addition and Subtraction
754. Reach a Number
43. Multiply Strings
525. Contiguous Array
Ugly Number
812. Largest Triangle Area
789. Escape The Ghosts
829. Consecutive Numbers Sum
Binary Search
658. Find K Closest Elements
744. Find Smallest Letter Greater Than Target