LeetCode刷题汇总(长期置顶)



之前就刷过 LeetCode,最近实在是被 Virtual Judge 的速度逼疯了,用了一波 LeetCode感觉除了题目较少以外真的很棒,搞个汇总贴,用点时间尽快考虑刷完大部分的LeetCode的题目.以前有一段时间(大概一两个星期?)集中干掉了大部分 leetcode的 easy,那些题目就不做汇总了,太 easy 了.碰到稍微复杂的题目我会专门写个博客贴代码讲解

工作太忙了^_^,也没有那么多时间刷题

—————————————————————————————————————————————————-

2019-02-14 更新: 过年期间事儿比较多没有刷题,今天起继续



2019-04-08 更新: 学到一个重要优化

Vectorized arraycopy in the `Object[] toArray()` case is much faster than the type-checked arraycopy in `toArray(new T[size])` and `toArray(new T[0])`. Alas, that does not help us if we want to get `T[].

要用collection.toArray(new T[0])代替collection.toArray(new T[size]),这样效率更高,详情有时间看一下这篇 blogArrays of Wisdom of the Ancients,感谢作者

Java 的 PriorityQueue 有个坑点

堆排序只会保证第一个元素也就是根节点的元素是当前优先队列里最小(或者最大)的元素,而且每一次变化之后,比如offer()或者poll()之后,都会进行堆重排,即堆不保证所有元素都被排序

table order by date

题目编号 博客地址 代码击败百分比 难度 语言 日期
1 two-sum 47.76% Easy Java 2019-01-17
15 3sum 38.19% Medium Java 2019-01-17
16 3Sum Closest 11.67% Medium Java 2019-01-17
18 4sum 27.97% Medium Java 2019-01-17
488 Zuma Game 100% Hard Java 2019-01-28
91 Decode Ways 91.16%/9.52% Medium Java 2019-01-29
60 Permutation Sequence 44.44%/71.49% Medium Java 2019-01-29
826 Most Profit Assigning Work 37.5%/60.72% Medium Java 2019-01-30
509 fibonacci-number 100% Easy Java 2019-01-30
169 Majority Element 100% Easy Java 2019-01-31
229 Majority Element II 97.92% Medium Java 2019-01-31
713 Subarray Product Less Than K 95.16% Medium Java 2019-02-02
152 Maximum Product Subarray 98.58% Medium Java 2019-02-02
560 Subarray Sum Equals K 99.05% Medium Java 2019-02-03
523 Continuous Subarray Sum 99.02% Medium Java 2019-02-03
923 3Sum With Multiplicity 6.75%/99.17% Medium Java 2019-02-14
821 Shortest Distance to a Character 23.71%/95.72% Easy Java 2019-02-14
206 Reverse Linked List 100% Easy Java 2019-02-18
2 Add Two Numbers 92% Medium Java 2019-02-19
3 Longest Substring Without Repeating 86.07% Medium Java 2019-02-19
4 Median of Two Sorted Arrays 89.58% Hard Java 2019–02-22
5 Longest Palindromic Substring 98.7% Medium Java 2019-02-22
6 ZigZag Conversion 95.57% Medium Java 2019-02-22
146 LRU Cache 92.45% Hard Java 2019-02-23
75 Sort Colors 100% Medium Java 2019-02-23
50 Pow(x, n) 99.44% Medium Java 2019-02-23
33 Search in Rotated Sorted Array 100% Medium Java 2019-02-25
215 Kth Largest Element in an Array 83.21% Medium Java 2019-02-25
53 Maximum Subarray 99.95% Easy Java 2019-02-25
58 Length of Last Word 100% Easy Java 2019-02-25
62 Unique Paths 100% Medium Java 2019-02-26
94 Binary Tree Inorder Traversal 100% Medium Java 2019-02-26
112 Path Sum 100% Easy Java 2019-02-27
113 Path Sum II 53.87% Medium Java 2019-02-27
124 Binary Tree Maximum 99.82% Hard Java 2019-02-28
138 Copy List with Random Pointer 100% Medium Java 2019-03-01
904 Fruit Info Baskets 53.07%/100% Medium Java 2019-03-01
42 Trapping Rain Water 99.98% Hard Java 2019-03-03
746 Min Cost Climbing Stairs 99.39% Easy Java 2019-03-04
235 Lowest Common Ancestor of a Binary Search Tree 100% Easy Java 2019-03-04
236 Lowest Common Ancestor of a Binary Tree 5.06%/91.03% Medium Java 2019-03-04
56 Merge Intervals 44.68% Medium Java 2019-03-05
435 Non-overlapping Intervals 100% Medium Java 2019-03-05
23 Merge k Sorted Lists 30.99% Hard Java 2019-03-06
301 Remove Invalid Parentheses 40.07% Hard Java 2019-03-07
253 Meeting Rooms II 39.88%/33.27% Medium Java 2019-03-08
252 Meeting Rooms 37.22%/99.94% Easy Java 2019-03-09
11 Container With Most Water 100% Medium Java 2019-03-09
446 Arithmetic Slices II - Subsequence 83.60% Hard Java 2019-03-10
654 Maximum Binary Tree 100% Medium Java 2019-03-10
238 Product of Array Except Self 100% Medium Java 2019-03-11
22 Generate Parentheses 100% Medium Java 2019-03-11
31 Next Permutation 97.09% Medium Java 2019-03-12
322 Coin Change 61.45% Medium Java 2019-03-12
8 String to Integer (atoi) 85.92% Medium Java 2019-03-13
10 Regular Expression Matching 14.68% Hard Java 2019-03-14
54 Spiral Matrix 100% Medium Java 2019-03-17
289 Game of Life 100% Medium Java 2019-03-17
84 Largest Rectangle in Histogram 98.93% Hard Java 2019-03-18
85 Maximal Rectangle 48.48%/91.26% Hard Java 2019-03-20
88 Merge Sorted Array 33.42% Easy Java 2019-03-21
41 First Missing Positive 85.07% Hard Java 2019-03-22
380 Insert Delete GetRandom O(1) 99.21% Medium Java 2019-03-22
621 Task Scheduler 91.60% Medium Java 2019-03-23
76 Minimum Window Substring 53.12% Hard Java 2019-03-25
771 Jewels and Stones 100% Easy Java 2019-03-26
811 Subdomain Visit Count 38.70% Easy Java 2019-03-26
49 Group Anagrams 99.80% Medium Java 2019-03-26
336 Palindrome Pairs 77.58% Hard Java 2019-03-27
347 Top K Frequent Elements 42.46% Medium Java 2019-03-28
692 Top K Frequent Words 97.72% Medium Java 2019-03-28
706 Design HashMap 83.26% Easy Java 2019-03-29
149 Max Points on a Line 47.39% Hard Java 2019-03-29
36 Valid Sudoku 99.68% Medium Java 2019-03-30
37 Sudoku Solver 29.90% Hard Java 2019-03-30
51 N-Queens 73.87% Hard Java 2019-03-30
939 Minimum Area Rectangle 75.67% Medium Java 2019-03-30
143 Reorder List 5.04% Medium Java 2019-04-01
92 Reverse Linked List II 100% Medium Java 2019-04-01
25 Reverse Nodes in k-Group 89.88% Hard Java 2019-04-02
19 Remove Nth Node From End of List 100% Medium Java 2019-04-03
445 Add Two Numbers II 90.08% Medium Java 2019-04-03
426 Convert Binary Search Tree to Sorted Doubly Linked List 100% Medium Java 2019-04-06
148 Sort List 97.95% Medium Java 2019-04-07
142 Linked List Cycle II 100% Medium Java 2019-04-07
430 Flatten a Multilevel Doubly Linked List 84.34% Medium Java 2019-04-08
986 Interval List Intersections 99.92% Medium Java 2019-04-08
273 Integer to English Words 50.07% Hard Java 2019-04-09
13 Roman to Integer 100% Easy Java 2019-04-10
528 Random Pick with Weight 61.90% Medium Java 2019-04-11
222 Count Complete Tree Nodes 100% Medium Java 2019-04-12
300 Longest Increasing Subsequence 68.17%/88.95% Medium Java 2019-04-13
34 Find First and Last Position of Element in Sorted Array 100% Medium Java 2019-04-13
981 Time Based Key-Value Store 98.27% Medium Java 2019-04-15
410 Split Array Largest Sum 100% Hard Java 2019-04-16
973 K Closest Points to Origin 6.80% Medium Java 2019-04-17
28 Implement strStr() 52.10% Easy Java 2019-04-18
312 Burst Balloons 86.81% Hard Java 2019-04-22
77 Combinations 34.40% Medium Java 2019-04-23
46 Permutations 99.82% Medium Java 2019-04-24
17 Letter Combinations of a Phone Number 88.81% Medium Java 2019-04-24
39 Combination Sum 99.96% Medium Java 2019-04-24
224 Basic Calculator 94.17% Hard Java 2019-04-25
975 Odd Even Jump 98.37% Hard Java 2019-04-28
103 Binary Tree Zigzag Level Order Traversal 75.42% Medium Java 2019-04-29
394 Decode String 88.95% Medium Java 2019-05-01
341 Flatten Nested List Iterator 100% Medium Java 2019-05-02
227 Basic Calculator II 55.00% Medium Java 2019-05-05
772 Basic Calculator III 82.75% Hard Java 2019-05-06
295 Find Median from Data Stream 90.40% Hard Java 2019-05-07
239 Sliding Window Maximum 59.93% Hard Java 2019-05-08
218 The Skyline Problem 48.78% Hard Java 2019-05-09
月月说要给我打赏,就还是放了二维码,😝