LeetCode 解题攻略——Kotlin

引言

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

汇总

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

Easy

# Title
717 1-bit and 2-bit Characters
804 Unique Morse Code Words
929 Unique Email Addresses
653 Two Sum IV - Input is a BST
709 To Lower Case
404 Sum of Left Leaves
905 Sort Array By Parity
922 Sort Array By Parity II
700 Search in a Binary Search Tree
938 Range Sum of BST
883 Projection Area of 3D Shapes
762 Prime Number of Set Bits in Binary Representation
852 Peak Index in a Mountain Array
876 Middle of the Linked List
771 Jewels and Stones
897 Increasing Order Search Tree
832 Flipping an Image
744 Find Smallest Letter Greater Than Target
760 Find Anagram Mappings
448 Find All Numbers Disappeared in an Array
942 DI String Match
944 Delete Columns to Make Sorted
696 Count Binary Substrings
538 Convert BST to Greater Tree
606 Construct String from Binary Tree
961 N-Repeated Element in Size 2N Array
977 Squares of a Sorted Array
965 Univalued Binary Tree
509 Fibonacci Number
985 Sum of Even Numbers After Queries
933 Number of Recent Calls
821 Shortest Distance to a Character
872 Leaf-Similar Trees
908 Smallest Range I
1002 Find Common Characters
836 Rectangle Overlap
783 Minimum Distance Between BST Nodes
303 Range Sum Query - Immutable
530 Minimum Absolute Difference in BST
645 Set 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
1021 Remove Outermost Parentheses
1266 Minimum Time Visiting All Points
1266 Truncate Sentence
1732 Find the Highest Altitude
1854 Maximum Population Year
1370 Increasing Decreasing String
1528 Shuffle String
1470 Shuffle the Array
1480 Running Sum of 1d Array
28 Implement strStr()
35 Search Insert Position
88 Merge Sorted Array
9 Palindrome Number
94 Binary Tree Inorder Traversal
543 Diameter of Binary Tree
14 Longest Common Prefix
1859 Sorting the Sentence

Medium

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

Hard

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

总结

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,684评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,143评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,214评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,788评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,796评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,665评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,027评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,679评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,346评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,664评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,766评论 1 331
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,412评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,015评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,974评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,073评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,501评论 2 343

推荐阅读更多精彩内容