LeetCode 解题攻略——Kotlin

1,038 阅读4分钟

引言

这篇文章的输出并不是作者计划好的,它来源于作者的一个习惯。这个习惯就是每周都会解决一道LeetCode的题目,从毕业至今一直保持着。最近突然发现每周的一道题和一篇解题思路的文章已经累积到60+,于是水到渠成地决定写下这篇汇总文章,既是对过去的总结,也希望能对他人有一些启发。

汇总

已经完成的LeetCode题目按问题难度汇总到下方的表格,分为Easy/Medium/Hard三部分,Title列点击题目可以跳转到该题答案和解题思路。

Easy

#Title
7171-bit and 2-bit Characters
804Unique Morse Code Words
929Unique Email Addresses
653Two Sum IV - Input is a BST
709To Lower Case
404Sum of Left Leaves
905Sort Array By Parity
922Sort Array By Parity II
700Search in a Binary Search Tree
938Range Sum of BST
883Projection Area of 3D Shapes
762Prime Number of Set Bits in Binary Representation
852Peak Index in a Mountain Array
876Middle of the Linked List
771Jewels and Stones
897Increasing Order Search Tree
832Flipping an Image
744Find Smallest Letter Greater Than Target
760Find Anagram Mappings
448Find All Numbers Disappeared in an Array
942DI String Match
944Delete Columns to Make Sorted
696Count Binary Substrings
538Convert BST to Greater Tree
606Construct String from Binary Tree
961N-Repeated Element in Size 2N Array
977Squares of a Sorted Array
965Univalued Binary Tree
509Fibonacci Number
985Sum of Even Numbers After Queries
933Number of Recent Calls
821Shortest Distance to a Character
872Leaf-Similar Trees
908Smallest Range I
1002Find Common Characters
836Rectangle Overlap
783Minimum Distance Between BST Nodes
303Range Sum Query - Immutable
530Minimum Absolute Difference in BST
645Set Mismatch
1221 Split a String in Balanced Strings
1252 Cells with Odd Values in a Matrix
189 Rotate Array
896 Monotonic Array
1013 Partition Array Into Three Parts With Equal Sum
172 Factorial Trailing Zeroes
237 Delete Node in a Linked List
1185 Day of the Week
917 Reverse Only Letters
811 Subdomain Visit Count
1184 Distance Between Bus Stops
1323 Maximum 69 Number
1572 Matrix Diagonal Sum
1704 Determine if String Halves Are Alike
1304 Find N Unique Integers Sum up to Zero

Medium

#Title
861Score After Flipping Matrix
950Reveal Cards In Increasing Order
763Partition Labels
921Minimum Add to Make Parentheses Valid
807Max Increase to Keep City Skyline
701Insert into a Binary Search Tree
515Find Largest Value in Each Tree Row
890Find and Replace Pattern
814Binary Tree Pruning
797All Paths From Source to Target
894All Possible Full Binary Trees
399Evaluate Division
328Odd Even Linked List
163Sum Closest
147Insertion Sort List
802Find Eventual Safe States
59Spiral Matrix II
162Find Peak Element
56Merge Intervals
831Masking Personal Information
725Split Linked List in Parts
855Exam Room
791Custom Sort String
1038Binary Search Tree to Greater Sum Tree
380Insert Delete GetRandom O(1)
516Longest Palindromic Subsequence
1008Construct Binary Search Tree from Preorder Traversal
93Restore IP Addresses
912Sort an Array
63Unique Paths II
910Smallest Range II
109Convert Sorted List to Binary Search Tree
64Minimum Path Sum
1282Group the People Given the Group Size They Belong To
43Multiply Strings
990Satisfiability of Equality Equations
655Print Binary Tree
260Single Number III
1238Circular Permutation in Binary Representation
667Beautiful Arrangement II
1006Clumsy Factorial
113Path Sum II
769Max Chunks To Make Sorted
962Maximum Width Ramp
462Minimum Moves to Equal Array Elements II
98Validate Binary Search Tree
1395Count Number of Teams
1315Sum of Nodes with Even-Valued Grandparent
1637Widest Vertical Area Between Two Points Containing No Points
1302Deepest Leaves Sum
1329Sort the Matrix Diagonally
1325Delete Leaves With a Given Value
1382Balance a Binary Search Tree
1476Subrectangle Queries
1669Merge In Between Linked Lists
1409Queries on a Permutation With Key
1630Arithmetic Subarrays
2Add Two Numbers
1605Find Valid Matrix Given Row and Column Sums
1551Minimum Operations to Make Array Equal
1641Count Sorted Vowel Strings

Hard

#Title
57Insert Interval
446Arithmetic Slices II - Subsequence
410Split Array Largest Sum
51N-Queens
928Minimize Malware Spread II
943Find the Shortest Superstring
312Burst Balloons
330Patching Array
1206Design Skiplist
32Longest Valid Parentheses

总结

不积跬步,无以至千里;不积小流,无以成江海。作者毕业至今保持着每周一道LeetCode的习惯,不知不觉中已经完成了100+的题目。通过梳理题目,总结解题思路,解题的效率也越来越高,效果还是很明显的。很推荐大家通过做LeetCode题目的方式保持思维的活跃,从枯燥的业务中适当释放一下,既能提高逻辑思维能力,也能提高对算法和数据结构的理解。