Skip to content

maxyzli/leetcode

Repository files navigation

LeetCode

 

LeetCode Solution in Java

Topics

Math

# Title Solution Difficulty
8 Reverse Integer Java Easy
9 Palindrome Number Java Easy
43 Multiply Strings (Classic) Java Medium
50 Pow(x, n) Java Medium
66 Plus One Java Easy
67 Add Binary Java Easy
204 Count Primes Java Easy
415 Add Strings Java Easy
989 Add to Array-Form of Integer Java Easy
1232 Check If It Is a Straight Line Java Easy

Bit

# Title Solution Difficulty
136 Single Number Java Easy
190 Reverse Bit Java Easy
191 Number of 1 Bits Java Easy
231 Power of Two Java Easy
371 Sum of Two Integers Java Medium
389 Find the Difference Java Easy
461 Hamming Distance Java Easy
477 Total Hamming Distance Java Medium

Array/String

# Title Solution Difficulty
1 Two Sum Java Easy
6 ZigZag Conversion Java Medium
8 String to Integer (atoi) (Classic) Java Medium
12 Integer to Roman Java Medium
13 Roman to Integer Java Easy
15 3Sum Java Medium
18 4Sum Java Medium
26 strStr (Classic) Java Easy
31 Next Permutation (Classic) Java Medium
32 Longest Valid Parentheses Java Hard
33 Search in Rotated Sorted Array (Classic) Java Medium
34 Find First and Last Position of Element in Sorted Array (Classic) Java Medium
35 Search Insert Position (Classic) Java Easy
38 Count and Say Java Medium
56 Merge Intervals (Classic) Java Medium
57 Insert Interval (Classic) Java Medium
58 Length of Last Word Java Easy
88 Merge Sorted Array Java Medium
118 Pascal's Triangle Java Easy
119 Pascal's Triangle II Java Easy
135 Candy Java Hard
153 Find Minimum in Rotated Sorted Array (Classic) Java Medium
154 Find Minimum in Rotated Sorted Array II Java Hard
162 Find Peak Element Java Medium
163 Missing Ranges Java Easy
164 Maximum Gap Java Hard
165 Compare Version Numbers Java Medium
167 Two Sum II - Input array is sorted Java Easy
179 Largest Number (Classic) Java Medium
186 Reverse Words in a String II Java Medium
189 Rotate Array Java Medium
228 Summary Ranges Java Easy
238 Product of Array Except Self (Classic) Java Medium
271 Encode and Decode Strings Java Medium
278 First Bad Version Java Easy
345 Reverse Vowels of a String Java Easy
349 Intersection of Two Arrays Java Easy
350 Intersection of Two Arrays II Java Easy
414 Third Maximum Number (Classic) Java Easy
442 Find All Duplicates in an Array Java Medium
448 Find All Numbers Disappeared in an Array Java Easy
459 Repeated Substring Pattern Java Easy
485 Max Consecutive Ones Java Easy
509 Fibonacci Number Java Easy
541 Reverse String II Java Easy
557 Reverse Words in a String III Java Easy
605 Can Place Flowers Java Easy
628 Maximum Product of Three Numbers Java Easy
665 Non-decreasing Array Java Medium
704 Binary Search Java Easy
852 Peak Index in a Mountain Array Java Easy
860 Lemonade Change Java Easy
905 Sort Array By Parity Java Easy
922 Sort Array By Parity II Java Easy
941 Valid Mountain Array Java Easy
1002 Find Common Characters Java Easy
1095 Find in Mountain Array Java Hard
1108 Defanging an IP Address Java Easy
1370 Increasing Decreasing String Java Easy
1480 Running Sum of 1d Array Java Easy
1502 Can Make Arithmetic Progression From Sequence Java Easy

Two Pointers

# Title Solution Difficulty
11 Container With Most Water Java Medium
26 Remove Duplicates from Sorted Array Java Easy
27 Remove Element Java Easy
42 Trapping Rain Water (Classic) Java Hard
80 Remove Duplicates from Sorted Array II (Classic) Java Medium
75 Sort Colors Java Medium
125 Valid Palindrome Java Easy
283 Move Zeroes Java Easy
344 Reverse String Java Easy
845 Longest Mountain in Array Java Medium
1119 Remove Vowels from a String Java Easy

Sliding Window

# Title Solution Difficulty
3 Longest Substring Without Repeating Characters Java Medium
76 Minimum Window Substring (Classic) Java Hard
209 Minimum Size Subarray Sum Java Medium
487 Max Consecutive Ones II Java Medium
567 Permutation in String (Classic) Java Medium
643 Maximum Average Subarray I Java Easy
1004 Max Consecutive Ones III Java Medium
1151 Minimum Swaps to Group All 1's Together (Classic) Java Medium

Matrix

# Title Solution Difficulty
36 Valid Sudoku Java Medium
48 Rotate Image (Classic) Java Medium
54 Spiral Matrix (Classic) Java Medium
59 Spiral Matrix II Java Medium
73 Set Matrix Zeroes (Classic) Java Medium
74 Search a 2D Matrix Java Medium
130 Surrounded Regions Java Medium
200 Number of Islands Java Medium
240 Search a 2D Matrix II Java Medium
463 Island Perimeter Java Easy
498 Diagonal Traverse Java Medium
529 Minesweeper Java Medium
695 Max Area of Island Java Medium
733 Flood Fill Java Easy
867 Transpose Matrix Java Easy
994 Rotting Oranges Java Medium
1034 Coloring A Border Java Medium

Linked List

# Title Solution Difficulty
2 Add Two Numbers Java Medium
19 Remove Nth Node From End of List Java Medium
21 Merge Two Sorted Lists Java Easy
25 Reverse Nodes in k-Group (Classic) Java Hard
82 Remove Duplicates from Sorted List II (Classic) Java Medium
83 Remove Duplicates from Sorted List (Classic) Java Easy
138 Copy List with Random Pointer (Classic) Java Medium
141 Linked List Cycle Java Easy
142 Linked List Cycle II Java Medium
143 Reorder List Java Medium
147 Insertion Sort List Java Medium
148 Sort List Java Medium
160 Intersection of Two Linked Lists Java Easy
203 Remove Linked List Elements Java Easy
206 Reverse Linked List Java Easy
234 Palindrome Linked List (Classic) Java Easy
328 Odd Even Linked List Java Medium
445 Add Two Numbers II Java Medium
707 Design Linked List Java Medium
876 Middle of the Linked List Java Easy
1265 Print Immutable Linked List in Reverse Java Easy

Hash Table

# Title Solution Difficulty
41 First Missing Positive (Classic) Java Hard
49 Group Anagrams Java Medium
128 Longest Consecutive Sequence Java Hard
205 Isomorphic Strings Java Easy
242 Valid Anagram Java Easy
290 Word Pattern Java Easy
554 Brick Wall Java Medium
560 Subarray Sum Equals K (Classic) Java Medium
771 Jewels and Stones Java Easy
888 Fair Candy Swap Java Easy
1122 Relative Sort Array Java Easy

Stack/Queue

# Title Solution Difficulty
20 Valid Parentheses Java Easy
71 Simplify Path Java Medium
84 Largest Rectangle in Histogram (Classic) Java Hard
155 Min Stack Java Easy
224 Basic Calculator (Classic) Java Hard
227 Basic Calculator II (Classic) Java Medium
225 Implement Stack using Queues Java Easy
232 Implement Queue using Stacks Java Easy
394 Decode String (Classic) Java Medium
739 Daily Temperatures Java Medium
946 Validate Stack Sequences (Classic) Java Medium
1047 Remove All Adjacent Duplicates In String Java Easy

Tree

Important

# Title Solution Difficulty
94 Binary Tree Inorder Traversal Java Easy
98 Validate Binary Search Tree Java Medium
100 Same Tree Java Easy
101 Symmetric Tree Java Easy
102 Binary Tree Level Order Traversal Java Medium
103 Binary Tree Zigzag Level Order Traversal Java Medium
104 Maximum Depth of Binary Tree Java Easy
107 Binary Tree Level Order Traversal II Java Medium
110 Balanced Binary Tree Java Easy
111 Minimum Depth of Binary Tree Java Easy
112 Path Sum Java Easy
114 Flatten Binary Tree to Linked List (Classic) Java Medium
116 Populating Next Right Pointers in Each Node Java Medium
129 Sum Root to Leaf Numbers Java Medium
144 Binary Tree Preorder Traversal Java Easy
173 Binary Search Tree Iterator Java Medium
199 Binary Tree Right Side View Java Medium
222 Count Complete Tree Nodes Java Medium
226 Invert Binary Tree Java Easy
235 Lowest Common Ancestor of a Binary Search Tree Java Easy
236 Lowest Common Ancestor of a Binary Tree Java Medium
257 Binary Tree Paths Java Easy
285 Inorder Successor in BST Java Medium
297 Serialize and Deserialize Binary Tree Java Hard
404 Sum of Left Leaves Java Easy
429 N-ary Tree Level Order Traversal Java Medium
515 Find Largest Value in Each Tree Row Java Medium
543 Diameter of Binary Tree Java Easy
589 N-ary Tree Preorder Traversal Java Easy
590 N-ary Tree Postorder Traversal Java Easy
653 Two Sum IV - Input is a BST Java Easy
662 Maximum Width of Binary Tree Java Medium
690 Employee Importance Java Easy
1120 Maximum Average Subtree Java Medium

Heap

# Title Solution Difficulty
23 Merge k Sorted Lists (Classic) Java Hard
215 Kth Largest Element in an Array Java Medium
239 Sliding Window Maximum (Classic) Java Hard
295 Find Median from Data Stream (Classic) Java Hard
347 Top K Frequent Elements (Classic) Java Medium
703 Kth Largest Element in a Stream Java Easy
973 K Closest Points to Origin Java Medium
1046 Last Stone Weight Java Easy

Graph

# Title Solution Difficulty
261 Graph Valid Tree Java Medium
323 Number of Connected Components in an Undirected Graph Java Medium

Greedy

# Title Solution Difficulty
45 Jump Game II Java Medium
55 Jump Game Java Medium
763 Partition Labels Java

Backtracking

# Title Solution Difficulty
17 Letter Combinations of a Phone Number Java Medium
22 Generate Parentheses Java Medium
37 Sudoku Solver (Classic) Java Hard
39 Combination Sum Java Medium
40 Combination Sum II (Classic) Java Medium
46 Permutations Java Medium
47 Permutations II (Classic) Java Medium
51 N-Queens (Classic) Java Hard
77 Combinations Java Medium
78 Subsets Java Medium
79 Word Search Java Medium
90 Subsets II (Classic) Java Medium
93 Restore IP Addresses (Classic) Java Medium
113 Path Sum II Java Medium
216 Combination Sum III Java Medium
301 Remove Invalid Parentheses (Classic) Java Hard
401 Binary Watch Java Easy
437 Path Sum III Java Medium
842 Split Array into Fibonacci Sequence Java Medium

Divide and Conquer

# Title Solution Difficulty
4 Median of Two Sorted Arrays (Classic) Java Hard
69 Sqrt(x) Java Easy
493 Reverse Pairs (Classic) Java Hard
1539 Kth Missing Positive Number (Classic) Java Easy

Dynamic Programming

Important

# Title Solution Difficulty
5 Longest Palindromic Substring (Classic) Java Medium
44 Wildcard Matching (Classic) Java Hard
53 Maximum Subarray Java Easy
62 Unique Paths Java Medium
63 Unique Paths II Java Medium
64 Minimum Path Sum (Classic) Java Medium
70 Climbing Stairs Java Easy
72 Edit Distance (Classic) Java Hard
85 Maximal Rectangle (Classic) Java Hard
96 Unique Binary Search Trees (Classic) Java Medium
115 Distinct Subsequences Java Hard
131 Palindrome Partitioning (Classic Java Medium
139 Word Break (Classic) Java Medium
152 Maximum Product Subarray Java Medium
198 House Robber Java Medium
213 House Robber II Java Medium
221 Maximal Square (Classic) Java Medium
300 Longest Increasing Subsequence (Classic) Java Medium
313 Super Ugly Number (Classic) Java Medium
322 Coin Change (Classic) Java Medium
343 Integer Break Java Medium
368 Largest Divisible Subset Java Medium
377 Combination Sum IV Java Medium
416 Partition Equal Subset Sum (Classic) Java Medium
486 Predict the Winner (Classic) Java Medium
516 Longest Palindromic Subsequence (Classic) Java Medium
518 Coin Change 2 (Classic) Java Medium
646 Maximum Length of Pair Chain Java Medium
647 Palindromic Substrings Java Medium
746 Min Cost Climbing Stairs Java Medium
1143 Longest Common Subsequence (Classic) Java Medium
1155 Number of Dice Rolls With Target Sum Java Medium

Trie

# Title Solution Difficulty
208 Implement Trie (Prefix Tree) Java Medium

Design

# Title Solution Difficulty
146 LRU Cache Java Medium
380 Insert Delete GetRandom O(1) Java Medium
1244 Design A Leaderboard Java Medium
1396 Design Underground System Java Medium

About

✍️ 200+ LeetCode solutions in Java

Topics

Resources

License

Stars

Watchers

Forks