Skip to content

Java Solutions to problems on LintCode/LeetCode

Notifications You must be signed in to change notification settings

cocoongg/LintCode

 
 

Repository files navigation

Java Algorithm Problems

程序员的一天

从开始这个Github已经有将近两年时间, 很高兴这个repo可以帮到有需要的人. 我一直认为, 知识本身是无价的, 因此每逢闲暇, 我就会来维护这个repo, 给刷题的朋友们一些我的想法和见解. 下面来简单介绍一下这个repo:

README.md: 所有所做过的题目

ReviewPage.md: 所有题目的总结和归纳(不断完善中)

KnowledgeHash2.md: 对所做过的知识点的一些笔记

SystemDesign.md: 对系统设计的一些笔记

Future Milestone: 我准备将一些有意思的题目,做成视频的形式给大家参考

希望大家学习顺利, 对未来充满希望(程序员也是找到好老板的!) 有问题可以给我写邮件(wangdeve@gmail.com), 或者在GitHub上发issue给我.

Squence Problem Level Language Tags Video Tutorial
0 Anagrams.java Medium Java []
1 Binary Representation.java Hard Java []
2 Binary Tree Level Order Traversal II.java Medium Java []
3 Binary Tree Level Order Traversal.java Medium Java []
4 Binary Tree Longest Consecutive Sequence.java Medium Java []
5 Binary Tree Maximum Path Sum II.java Medium Java []
6 Binary Tree Right Side View.java Medium Java []
7 Binary Tree Serialization.java Medium Java []
8 Binary Tree Zigzag Level Order Traversal.java Medium Java []
9 ColorGrid.java Medium Java []
10 Combination Sum II.java Medium Java []
11 Combination Sum.java Medium Java []
12 Combinations.java Medium Java []
13 Construct Binary Tree from Inorder and Postorder Traversal.java Medium Java []
14 Container With Most Water.java Medium Java []
15 Convert Binary Search Tree to Doubly Linked List.java Medium Java [BST]
16 Convert Expression to Polish Notation.java Hard Java []
17 Convert Expression to Reverse Polish Notation.java Hard Java []
18 Convert Integer A to Integer B.java Easy Java []
19 Copy List with Random Pointer.java Medium Java []
20 Cosine Similarity.java Easy Java []
21 Count 1 in Binary.java Easy Java []
22 Count and Say.java Easy Java []
23 Count of Smaller Number before itself.java Hard Java []
24 Count of Smaller Number.java Medium Java []
25 Count Primes.java Easy Java []
26 Delete Digits.java Medium Java []
27 Delete Node in the Middle of Singly Linked List.java Easy Java []
28 Encode and Decode Strings.java Medium Java []
29 ExcelSheetColumnNumber .java Easy Java []
30 Expression Evaluation.java Hard Java []
31 Expression Tree Build.java Hard Java []
32 Fast Power.java Medium Java []
33 Fibonacci.java Easy Java []
34 Find the Connected Component in the Undirected Graph.java Medium Java []
35 Find the Weak Connected Component in the Directed Graph.java Medium Java []
36 First Missing Positive.java N/A Java []
37 Flatten 2D Vector.java Medium Java []
38 Flip Game II.java Medium Java []
39 Flip Game.java Easy Java []
40 Fraction to Recurring Decimal.java Medium Java []
41 Gas Station.java N/A Java []
42 Generate Parentheses.java Medium Java []
43 Gray Code.java Medium Java []
44 Group Anagrams.java Medium Java []
45 Group Shifted Strings.java Easy Java []
46 H-Index II.java Medium Java []
47 H-Index.java Medium Java []
48 Hamming Distance.java Easy Java []
49 Happy Number.java Easy Java []
50 Hash Function.java Easy Java []
51 HashHeap.java Hard Java []
52 HashWithArray.java Easy Java []
53 HashWithCustomizedClass(LinkedList).java Medium Java []
54 Heapify.java Medium Java []
55 Heaters.java Easy Java []
56 Identical Binary Tree.java Easy Java []
57 Implement Queue by Two Stacks.java N/A Java []
58 Implement Stack by Two Queues.java Easy Java []
59 Implement Stack using Queues.java Easy Java []
60 Implement Stack.java Easy Java []
61 Implement strStr().java N/A Java []
62 Implement Trie (Prefix Tree).java Medium Java []
63 IndexMatch.java Easy Java []
64 Inorder Successor in Binary Search Tree.java Medium Java [BST]
65 Insert Interval.java Easy Java []
66 Insert Node in a Binary Search Tree .java Easy Java [BST]
67 Insertion Sort List.java N/A Java []
68 Integer to English Words.java N/A Java []
69 Interleaving Positive and Negative Numbers.java N/A Java []
70 Intersection of Two Arrays.java Easy Java []
71 Intersection of Two Linked Lists.java Easy Java []
72 Interval Minimum Number.java Medium Java []
73 Interval Sum II.java Hard Java []
74 Interval Sum.java Medium Java []
75 Invert Binary Tree.java Easy Java []
76 Isomorphic Strings.java Easy Java []
77 Jump Game II.java Hard Java []
78 Kth Largest Element.java Medium Java []
79 Kth Smallest Element in a BST.java Medium Java [BST]
80 Kth Smallest Sum In Two Sorted Arrays.java Hard Java []
81 Largest Number.java N/A Java []
82 Last Position of Target.java N/A Java []
83 Length of Last Word.java N/A Java []
84 Longest Common Prefix.java Medium Java []
85 Longest Common Substring.java N/A Java []
86 Longest Consecutive Sequence.java N/A Java []
87 Longest Increasing Continuous subsequence II.java N/A Java []
88 Longest Increasing Continuous subsequence.java Easy Java []
89 Longest Palindromic Substring.java Medium Java []
90 Longest Univalue Path.java Easy Java []
91 Longest Word in Dictionary.java Easy Java []
92 Longest Words.java N/A Java []
93 Lowest Common Ancestor II.java Easy Java []
94 Lowest Common Ancestor of a Binary Search Tree.java Medium Java []
95 Lowest Common Ancestor.java Easy Java []
96 LRU Cache.java Hard Java []
97 Majority Number II.java Medium Java []
98 Majority Number III.java Medium Java []
99 Matrix Zigzag Traversal.java Easy Java []
100 Max Area of Island.java Easy Java []
101 Maximum Depth of Binary Tree.java Easy Java []
102 Maximum Subarray III.java N/A Java []
103 Maximum Subarray.java Easy Java []
104 Maximum SubarrayII.java N/A Java []
105 MaximumSubarrayII.java N/A Java []
106 Median of two Sorted Arrays.java Hard Java []
107 Median.java N/A Java []
108 Merge Intervals.java Easy Java []
109 Merge k Sorted Arrays.java Medium Java []
110 Merge k Sorted Lists.java Medium Java []
111 Merge Sorted Array II.java N/A Java []
112 Merge Sorted Array.java Easy Java []
113 Merge Two Binary Trees.java Easy Java []
114 Merge Two Sorted Lists.java Easy Java []
115 Middle of Linked List.java N/A Java []
116 Minimum Absolute Difference in BST.java Easy Java [BST]
117 Minimum Height Trees.java N/A Java []
118 Minimum Subarray.java N/A Java []
119 MinimumDepthOfBinaryTree.java Easy Java []
120 Missing Ranges.java N/A Java []
121 Multiply Strings.java Medium Java []
122 Next Permutation.java Medium Java []
123 NQueens.java N/A Java []
124 NQueensII.java N/A Java []
125 Nth to Last Node in List.java N/A Java []
126 Number Triangles.java N/A Java []
127 O(1) Check Power of 2.java N/A Java []
128 One Edit Distance.java Medium Java []
129 Paint Fence.java N/A Java []
130 Palindrome Linked List.java N/A Java []
131 Palindrome Partitioning.java N/A Java []
132 Palindrome Permutation II.java Medium Java []
133 Palindrome Permutation.java Easy Java []
134 Partition Array by Odd and Even.java N/A Java []
135 Partition Array.java N/A Java []
136 Partition List.java N/A Java []
137 Pascal's Triangle II.java Easy Java []
138 Peeking Iterator.java Medium Java [BST]
139 Permutation Index.java Easy Java []
140 Permutation Sequence.java Medium Java []
141 Permutations II.java Medium Java []
142 Permutations.java Medium Java []
143 Populating Next Right Pointers in Each Node II.java Hard Java []
144 Product of Array Exclude Itself.java N/A Java []
145 QuickSort.java Easy Java []
146 Recover Rotated Sorted Array.java N/A Java []
147 Rehashing.java Medium Java []
148 Remove Duplicates from Sorted Array.java Easy Java []
149 Remove Duplicates from Sorted List II.java N/A Java []
150 Remove Duplicates from Sorted List.java Easy Java []
151 Remove Duplicates from Unsorted List.java N/A Java []
152 Remove Invalid Parentheses.java Hard Java []
153 Remove Linked List Elements.java N/A Java []
154 Remove Node in Binary Search Tree.java Hard Java [BST]
155 Reorder List.java N/A Java []
156 Reshape the Matrix.java Easy Java []
157 Restore IP Addresses.java N/A Java []
158 Reverse Linked List II .java N/A Java []
159 Reverse Linked List.java Easy Java []
160 Reverse String.java Easy Java []
161 Reverse Words in a String II.java Medium Java []
162 Reverse Words in a String.java Medium Java []
163 Roman to Integer.java Easy Java []
164 Rotate Image.java Medium Java []
165 Rotate List.java N/A Java []
166 Rotate String.java N/A Java []
167 Russian Doll Envelopes.java N/A Java []
168 Search a 2D Matrix II.java N/A Java []
169 Search a 2D Matrix.java N/A Java []
170 Search for a Range.java N/A Java []
171 Search Insert Position.java N/A Java []
172 Search Range in Binary Search Tree .java Medium Java [BST]
173 Search Rotated in Sorted Array II.java N/A Java []
174 Search Rotated in Sorted Array.java Hard Java []
175 Segment Tree Build II.java Medium Java []
176 Segment Tree Build.java Medium Java []
177 Segment Tree Modify.java Medium Java []
178 Segment Tree Query II.java Medium Java []
179 Segment Tree Query.java Medium Java []
180 Serilization and Deserialization Of Binary Tree.java N/A Java []
181 Shortest Word Distance.java Easy Java []
182 Single Number II.java N/A Java []
183 Single Number III.java N/A Java []
184 Single Number.java Easy Java []
185 Singleton.java N/A Java []
186 Sliding Window Maximum.java N/A Java []
187 Sort Color.java N/A Java []
188 Sort Colors II.java N/A Java []
189 Sort Letters by Case.java N/A Java []
190 Sort List.java N/A Java []
191 Space Replacement.java N/A Java []
192 Stone Game.java N/A Java []
193 String Permutation.java Easy Java []
194 String to Integer(atoi).java Easy Java []
195 Strobogrammatic Number II.java Medium Java []
196 Strobogrammatic Number.java Easy Java []
197 StrStr.java N/A Java []
198 Subarray Sum Closest.java Medium Java []
199 Subarray Sum.java Easy Java []
200 Subset.java Medium Java []
201 Subsets II.java Medium Java []
202 Subtree.java Easy Java []
203 Summary Ranges.java N/A Java []
204 Symmetric Binary Tree.java Easy Java []
205 The Smallest Difference.java N/A Java []
206 Top K Frequent Elements.java Medium Java []
207 Top K Frequent Words.java Medium Java []
208 Topological Sorting.java Medium Java []
209 Total Occurrence of Target.java N/A Java []
210 Trailing Zeros.java N/A Java []
211 Tweaked Identical Binary Tree.java Easy Java []
212 Two Lists Sum.java N/A Java []
213 Two Strings Are Anagrams.java Easy Java []
214 Ugly Number II.java N/A Java []
215 Ugly Number.java Medium Java []
216 Unique Binary Search Tree II.java Medium Java [BST]
217 Unique Characters.java N/A Java []
218 Unique Word Abbreviation.java N/A Java []
219 Valid Palindrome.java Easy Java []
220 Valid Parentheses.java Easy Java []
221 Valid Sudoku.java Easy Java []
222 Word Break.java Medium Java []
223 Word Ladder II.java Hard Java []
224 Word Ladder.java Medium Java []
225 Word Pattern.java Easy Java []
226 Zigzag Iterator.java Medium Java [BST]
227 Find Anagram Mappings.java Easy Java [Hash Table]
228 Judge Route Circle.java Easy Java [String]
229 Island Perimeter.java Easy Java [Hash Table]
230 First Unique Character in a String.java Easy Java [Hash Table, String]
231 Power of Three.java Easy Java [Math]
232 Plus One.java Easy Java [Array, Math]
233 Power of Two.java Easy Java [Bit Manipulation, Math]
234 Reverse Vowels of a String.java Easy Java [String, Two Pointers]
235 Guess Number Higher or Lower.java Easy Java [Binary Search]
236 Encode and Decode TinyURL.java Medium Java [Hash Table, Math]
237 Wiggle Sort.java Medium Java [Array, Sort]
238 Queue Reconstruction by Height.java Medium Java [Greedy]
239 2 Sum.java Easy Java [Array, Hash Table]
240 2 Sum II - Input array is sorted.java Medium Java [Array, Binary Search, Two Pointers]
241 2 Sum II.java Medium Java [Array, Binary Search, Two Pointers]
242 Coin Change.java Medium Java [DP]
243 Jump Game.java Medium Java [Array, Greedy]
244 Maximum Product Subarray.java Medium Java [Array, DP]
245 3 Sum Closest.java Medium Java [Array, Two Pointers]
246 Triangle Count.java Medium Java [Array]
247 3 Sum.java Medium Java [Array, Two Pointers]
248 4 Sum.java Medium Java [Hash Table]
249 k Sum.java Hard Java [DP]
250 Longest Continuous Increasing Subsequence.java Easy Java [Array, DP]
251 Longest Increasing Subsequence.java Medium Java [Binary Search, DP, Memoization, Sequence DP]
252 Unique Binary Search Tree.java Medium Java [BST, DP, Tree]
253 Trim a Binary Search Tree.java Easy Java [BST, Tree]
254 Unique Paths II.java Medium Java [Array, DP]
255 Counting Bits.java Medium Java [Bit Manipulation, DP]
256 Bomb Enemy.java Medium Java [DP]
257 Paint House.java Easy Java [DP]
258 Decode Ways.java Review Java [DP, String]
259 House Robber.java Easy Java [DP, Sequence DP]
260 House Robber II.java Medium Java [DP, Sequence DP]
261 Best Time to Buy and Sell Stock I.java Easy Java [Array, DP]
262 Best Time to Buy and Sell Stock II.java Easy Java [Array, Greedy]
263 Best Time to Buy and Sell Stock III .java Hard Java [Array, DP]
264 Best Time to Buy and Sell Stock IV.java Hard Java [DP]
265 Paint House II.java Review Java [DP]
266 3 Sum Smaller.java Medium Java [Array, Two Pointers]
267 Array Partition I.java Easy Java [Array]
268 1-bit and 2-bit Characters.java Easy Java [Array]
269 Non-decreasing Array.java Easy Java [Array]
270 Max Consecutive Ones.java Easy Java [Array]
271 Find All Numbers Disappeared in an Array.java Easy Java [Array]
272 Maximum Average Subarray I.java Easy Java [Array]
273 Largest Number At Least Twice of Others.java Easy Java [Array]
274 Toeplitz Matrix.java Easy Java [Array]
275 Backpack.java Medium Java [DP]
276 Sum of Two Integers.java Easy Java [Bit Manipulation]
277 Swap Bits.java Easy Java [Bit Manipulation]
278 Update Bits.java Medium Java [Bit Manipulation]
279 Maximum XOR of Two Numbers in an Array.java Medium Java [Bit Manipulation, Trie]
280 Perfect Squares.java Medium Java [BFS, DP, Math]
281 Palindrome Partitioning II.java Hard Java [DP]
282 Backpack V.java Medium Java [DP]
283 Backpack VI.java Medium Java [DP]
284 Copy Books.java Hard Java [Binary Search, DP]
285 Valid Perfect Square.java Review Java [Binary Search, Math]
286 Intersection of Two Arrays II.java Easy Java [Binary Search, Hash Table, Sort, Two Pointers]
287 Backpack II.java Medium Java [DP]
288 Backpack III.java Review Java [DP]
289 Longest Palindromic Subsequence.java Medium Java [DP]
290 Scramble String.java Hard Java [DP, String]
291 Binary Search Tree Iterator.java Medium Java [BST, Design, Stack, Tree]
292 Flatten Nested List Iterator.java Medium Java [Design, Stack]
293 Best Time to Buy and Sell Stock with Cooldown.java Medium Java [DP]
294 Find Peak Element.java Medium Java [Array, Binary Search]
295 Longest Common Subsequence.java Medium Java [DP]
296 Interleaving String.java Hard Java [DP, String]
297 Letter Combinations of a Phone Number.java Medium Java [Backtracking, String]
298 Edit Distance.java Hard Java [DP, String]
299 Distinct Subsequences.java Hard Java [DP, String]
300 Regular Expression Matching.java Review Java [Backtracking, DP, String]
301 Majority Element.java Easy Java [Array, Bit Manipulation, Divide and Conquer]
302 Wildcard Matching.java Hard Java [Backtracking, DP, Greedy, String]
303 Ones and Zeroes.java Hard Java [DP]
304 Pow(x,n).java Medium Java [Binary Search, Math]
305 Word Break II.java Review Java [Backtracking, DP]
306 Nested List Weight Sum.java Easy Java [DFS]
307 Same Tree.java Easy Java [DFS, Tree]
308 Convert Sorted Array to Binary Search Tree.java Easy Java [DFS, Tree]
309 Binary Tree Maximum Path Sum.java Review Java [DFS, Tree]
310 Construct Binary Tree from Inorder and Preorder Traversal.java Medium Java [Array, DFS, Tree]
311 Path Sum.java Easy Java [DFS, Tree]
312 Add Binary.java Easy Java [Math, String]
313 Add Digits.java Easy Java [Math]
314 Add Two Numbers.java Medium Java [Linked List, Math]
315 Add Two Numbers II.java Medium Java [Linked List]
316 Balanced Binary Tree.java Medium Java [DFS, Tree]
317 Valid Anagram.java Easy Java [Hash Table, Sort]
318 Populating Next Right Pointers in Each Node.java Medium Java [DFS, Tree]
319 Validate Binary Search Tree.java Medium Java [BST, DFS, Tree]
320 Convert Sorted List to Binary Search Tree.java Medium Java [DFS, Linked List]
321 Flatten Binary Tree to Linked List.java Medium Java [Binary Tree, DFS]
322 Binary Tree Paths.java Easy Java [Binary Tree, DFS]
323 Minimum Size Subarray Sum.java Medium Java [Array, Binary Search, Two Pointers]
324 Clone Graph.java Medium Java [BFS, DFS, Graph]
325 Longest Substring Without Repeating Characters.java Medium Java [Hash Table, String, Two Pointers]
326 Minimum Window Substring.java Hard Java [Hash Table, String, Two Pointers]
327 Linked List Cycle.java Easy Java [Linked List, Two Pointers]
328 Remove Nth Node From End of List.java Medium Java [Linked List, Two Pointers]
329 Longest Substring with At Most K Distinct Characters.java Medium Java [Hash Table, String]
330 Linked List Cycle II.java Medium Java [Linked List, Two Pointers]
331 Kth Smallest Number in Sorted Matrix.java Medium Java [Binary Search, Heap]
332 Find Minimum in Rotated Sorted Array.java Medium Java [Array, Binary Search]
333 Find Minimum in Rotated Sorted Array II.java Hard Java [Array, Binary Search]
334 Connecting Graph.java Medium Java [Union Find]
335 Connecting Graph II.java Medium Java [Union Find]
336 Connecting Graph III.java Medium Java [Union Find]
337 Number of Islands.java Medium Java [BFS, DFS, Union Find]
338 Number of Islands II.java Hard Java [Union Find]
339 Graph Valid Tree.java Medium Java [BFS, DFS, Graph, Union Find]
340 Surrounded Regions.java Review Java [BFS, DFS, Union Find]
341 Implement Trie.java Medium Java [Design, Trie]
342 Add and Search Word.java Medium Java [Backtracking, Design, Trie]
343 Word Search II.java Hard Java [Backtracking, DFS, Trie]
344 Word Search.java Medium Java [Array, Backtracking]
345 Word Squares.java Hard Java [Backtracking, Trie]
346 Trapping Rain Water.java Hard Java [Array, Stack, Two Pointers]
347 Trapping Rain Water II.java Hard Java [BFS, Heap]
348 Data Stream Median.java Hard Java [Design, Heap]
349 Sliding Window Median.java Hard Java [Design, Heap]
350 Min Stack.java Easy Java [Design, Stack]
351 Implement Queue using Stacks.java Easy Java [Design, Stack]
352 Expression Expand.java Medium Java [DFS, Divide and Conquer, Stack]
353 Largest Rectangle in Histogram.java Hard Java [Array, Monotonous Stack, Stack]
354 Max Tree.java Medium Java [Stack, Tree]
355 Reverse Integer.java Easy Java [Math]
356 Swap Nodes in Pairs.java Medium Java [Linked List]
357 Find Peak Element II.java Hard Java [Binary Search, DFS, Divide and Conquer]
358 Sqrt(x).java Easy Java [Binary Search, Math]
359 First Bad Version.java Easy Java [Binary Search]
360 Wood Cut.java Medium Java [Binary Search]
361 Find the Duplicate Number.java Medium Java [Array, Binary Search, Two Pointers]
362 Palindrome Pairs.java Hard Java [Hash Table, String, Trie]
363 Game of Life.java Medium Java [Array]
364 Maximum Average Subarray II.java Review Java [Array, Binary Search]
365 Meeting Rooms.java Easy Java [Sort, Sweep Line]
366 Number of Airplane in the sky.java Medium Java [Array, Interval, Sort, Sweep Line]
367 Meeting Rooms II.java Medium Java [Greedy, Heap, Sort, Sweep Line]
368 Building Outline.java Review Java [Binary Indexed Tree, Divide and Conquer, Heap, Segment Tree, Sweep Line]
369 Unique Path.java Medium Java [Array, Coordinate DP, DP]
370 Maximal Rectangle.java Hard Java [Array, DP, Hash Table, Stack]
371 Maximal Square.java Medium Java [Coordinate DP, DP]
372 Minimum Path Sum.java Medium Java [Array, Coordinate DP, DP]
373 House Robber III.java Hard Java [DFS, DP, Status DP, Tree]
374 Longest Increasing Path in a Matrix.java Hard Java [DFS, DP, Memoization, Topological Sort]
375 Coins in a Line.java Medium Java [DP, Game Theory, Greedy]
376 Coins in a Line II.java Medium Java [Array, DP, Game Theory, Memoization, MiniMax]
377 Binary Tree Inorder Traversal.java Easy Java [Hash Table, Stack, Tree]
378 Path Sum II.java Easy Java [DFS, Tree]
379 Binary Tree Postorder Traversal.java Medium Java [Stack, Tree, Two Stacks]
380 Change to Anagram.java Easy Java [String]
381 Classical Binary Search.java Easy Java [Binary Search]
382 Climbing Stairs.java Easy Java [DP, Memoization, Sequence DP]
383 Coins in a Line III.java Hard Java [Array, DP, Game Theory, Interval DP, Memoization]
384 Closest Binary Search Tree Value.java Easy Java [BST, Binary Search, Tree]
385 Compare Version Numbers.java Medium Java [String]
386 Count Complete Tree Nodes.java Medium Java [Binary Search, Tree]
387 Course Schedule.java Medium Java [BFS, DFS, Graph, Topological Sort]
388 Course Schedule II.java Medium Java [BFS, DFS, Graph, Topological Sort]
389 Alien Dictionary.java Hard Java [BFS, Backtracking, DFS, Graph, Topological Sort]
390 Binary Tree Preorder Traversal.java Easy Java [BFS, DFS, Stack, Tree]
391 Closest Number in Sorted Array.java Easy Java [Binary Search]
392 Complete Binary Tree.java Easy Java [BFS, DFS, Tree]
393 Compare Strings.java Easy Java [String]
394 Contains Duplicate.java Easy Java [Array, Hash Table]
395 Contains Duplicate II.java Easy Java [Array, Hash Table]
396 Contains Duplicate III.java Medium Java [BST]
397 Burst Balloons.java Hard Java [DP, Divide and Conquer, Memoization, Range DP]
398 Nim Game.java Easy Java [Brainteaser, DP, Game Theory]

About

Java Solutions to problems on LintCode/LeetCode

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%