Skip to content

rajeevranjancom/Leetcode_Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leetcode_Java@Rajeev Ranjan

Solution@Leetcode

Links:

Websites
https://docs.oracle.com/en/java/ (Java Documentation)
https://docs.oracle.com/en/java/javase/15/ (JDK 15 Documentation)
https://docs.oracle.com/javacomponents/ (Java Components)
https://docs.oracle.com/javaee/7/index.html (Java Platform, Enterprise Edition (Java EE) 7)
https://docs.oracle.com/javame/8.3/index.html (Java Platform, Micro Edition Embedded (Java ME Embedded) 8.3)
https://docs.oracle.com/javase/8/javase-embedded.htm (Java Platform, Standard Edition (Java SE) 8)
https://docs.oracle.com/en/java/javacard/3.1/ (Java Card 3.1 Documentation)
https://docs.oracle.com/en/java/javacard/3.1/books.html (Release Notes and Books)
https://docs.oracle.com/en/java/javase/15/docs/api/index.html (Java® Platform, Standard Edition & Java Development Kit
Version 15 API Specification)
https://www.java.com/ES/download/ (Java Download)
https://www.oracle.com/in/java/technologies/javase-downloads.html (Java SE Downloads)

Notes:

Important
Java is a set of computer software and specifications developed by James Gosling at Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cross-platform computing environment
Initial release date: 23 January 1996
Developed by: Sun Microsystems
Original author(s) James Gosling, Sun Microsystems
Developer(s) Oracle Corporation
Operating system Microsoft Windows, Solaris, Linux, macOS
Platform IA-32, x64, ARMv7, ARMv8, SPARC (up to Java 14) (Java 8 includes 32-bit support – while no longer supported freely by Oracle for commercial use – 32- bit platforms are not supported in other versions, since dropped officially in Java 10.)
Available in English, Chinese, French, German, Italian, Japanese, Korean, Portuguese, Spanish, Swedish

Table:

Question Solution Difficulty Tag
1. Two Sum Solution Easy Array / Hash Table
2. Add Two Numbers Solution Medium Linked List
3. Longest Substring Without Repeating Characters Solution Medium Hash Table / Two Pointers
4. Median of Two Sorted Arrays Solution Hard Array / Binary Search
5. Longest Palindromic Substring Solution Medium String
6. ZigZag Conversion Solution Medium String
7. Reverse_Integer Solution Medium Math
8. StringToInteger Solution Medium String
9. Palindrome Number Solution Easy Math
10. Regular Expression Matching Solution Hard String / Dynamic Programming / Backtracking
11. Container With Most Water Solution Medium Medium
12. Integer to Roman Solution Medium String
13. Roman to Integer Solution Easy String
14. Longest Common Prefix Solution Easy String
15. 3Sum Solution Medium Array / Two Pointers
16. 3Sum Closest Solution Medium Array / Two Pointers
17. Letter Combinations of a Phone Number Solution Medium Backtracking / String
18. 4Sum Solution Medium Array
19. Remove Nth Node From End of List Solution Medium Linked List / Two Pointers
20. Valid Parentheses Solution Easy Stack
21. Merge Two Sorted Lists Solution Easy Linked List
22. Generate Parentheses Solution Medium String / Backtracking
23. Merge k Sorted Lists Solution Hard Linked List / Heap
25. Reverse Nodes in k-Group Solution Hard Linked List
26. Remove Duplicates from Sorted Array Solution Easy Array / Two Pointers
28. Implement strStr() Solution Easy String
29. Divide Two Integers Solution Easy String
31. Next Permutation Solution Medium Array
32. Longest Valid Parentheses Solution Hard
33. Search in Rotated Sorted Array Solution Medium Array / Binary Search
34. Search for a Range Solution Medium Array / Binary Search
35. Search Insert Position Solution Easy Array / Binary Search
36. Valid Sudoku Solution Medium Hash Table
37. Sudoku Solver Solution Hard Hash Table
39. Combination Sum Solution Medium String
41. First Missing Positive Solution Hard Array
42. Trapping Rain Water Solution Hard Array / Two Pointers / Stack
43. Multiply Strings Solution Medium String
44. Wildcard Matching Solution Hard String / Backtracking / Greedy
45. Jump Game II Solution Hard Hard
46. Permutations Solution Medium Backtracking
47. Permutations II Solution Medium Backtracking
48. Rotate Image Solution Medium Matrix
49. Group Anagrams Solution Medium Hash Table / String
50. Pow(x, n) Solution Medium Binary Search
51. N-Queens Solution Hard Binary Search
52. N-Queens II Solution Hard Binary Search
53. Maximum Subarray Solution Easy Dynamic Programming / Array
54. Spiral Matrix Solution Medium Array
55. Jump Game Solution Medium Array / Greedy
56. Merge Intervals Solution Medium Medium
57. Insert Interval Solution Hard Hard
59. Spiral Matrix II Solution Medium Array
60. Permutation Sequence Solution Medium Backtracking / Math
61. Rotate List Solution Medium Linked List / Two Pointers
62. Unique Paths Solution Medium Array / Dynamic Programming
63. Unique Paths II Solution Medium Medium
64. Minimum Path Sum Solution Medium Array / Dynamic Programming
65. Valid Number Solution Hard Array / Dynamic Programming
66. Plus One Solution Easy Array / Math
68. Text Justification Solution Hard String
69. Sqrt(x) Solution Easy Binary Search / Math
70. Climbing Stairs Solution Easy Dynamic Programming
71. Simplify Path Solution Medium Stack / String
72. Edit Distance Solution Hard Stack / String
73. Set Matrix Zeroes Solution Medium Array
74. Search a 2D Matrix Solution Medium Array / Binary Search
75. Sort Colors Solution Medium Array / Two Pointers
76. Minimum Window Substring Solution Hard Hash Table / Two pointers / String
78. Subsets Solution Medium Array / Backtracking
79. Word Search Solution Medium Matrix / Backtracking
80. Remove Duplicates from Sorted Array II Solution Medium Array / Two Pointers
81. Search in Rotated Sorted Array II Solution Medium
82. Remove Duplicates from Sorted List II Solution Medium Linked List
83. Remove Duplicates from Sorted List Solution Easy Linked List
84. Largest Rectangle in Histogram Solution Hard Array
85. Maximal Rectangle Solution Hard Array
86. Partition List Solution Medium Linked List
88. Merge Sorted Array Solution Easy Array / Two Pointers
90. Subsets II Solution Medium Array / Backtracking
91. Decode Ways Solution Medium Dynamic Programming / String
92. Reverse Linked List II Solution Medium Linked List
93. Restore IP Addresses Solution Medium
94. Binary Tree Inorder Traversal Solution Medium Tree / Stack
95. Unique Binary Search Trees II Solution Medium Tree
96. Unique Binary Search Trees Solution Medium Tree / DFS
97. Interleaving String Solution Hard Tree / DFS
98. Validate Binary Search Tree Solution Medium Tree
100. Same Tree Solution Easy Tree / DFS
101. Symmetric Tree Solution Easy Tree
102. Binary Tree Level Order Traversal Solution Medium Tree / DFS / BFS
103. Binary Tree Zigzag Level Order Traversal Solution Medium Tree / BFS
104. Maximum Depth of Binary Tree Solution Easy Tree
105. Construct Binary Tree from Preorder and Inorder Traversal Solution Medium Array / Tree / DFS
106. Construct Binary Tree from Inorder and Postorder Traversal Solution Medium Linked List / DFS
107. Binary Tree Level Order Traversal II Solution Easy Tree
108. Convert Sorted Array to Binary Search Tree Solution Easy Tree / DFS
109. Convert Sorted List to Binary Search Tree Solution Medium Linked List / DFS
110. Balanced Binary Tree Solution Easy Tree / DFS
111. Minimum Depth of Binary Tree Solution Easy Tree
112. Path Sum Solution Easy Tree / DFS
113. Path Sum II Solution Medium Tree / DFS
114. Flatten Binary Tree to Linked List Solution Medium Tree / DFS
116. Populating Next Right Pointers in Each Node Solution Medium Tree / BFS
117. Populating Next Right Pointers in Each Node II Solution Medium Tree / Level-order Traversal
119. Pascal's Triangle II Solution Easy Array
120. Triangle Solution Medium Array / Dynamic Programming
121. Best Time to Buy and Sell Stock Solution Easy Array / Dynamic Programming
122. Best Time to Buy and Sell Stock II Solution Easy Tree / DFS
123. Best Time to Buy and Sell Stock III Solution Hard Tree / DFS
124. Binary Tree Maximum Path Sum Solution Hard Tree / DFS
125. Valid Palindrome Solution Easy String / Two Pointers
126. Word Ladder II Solution Hard Array / Unoin Find
127. Word Ladder Solution Medium String / BFS
128. Longest Consecutive Sequence Solution Hard Array / Unoin Find
129. Sum Root to Leaf Numbers Solution Medium Tree / DFS / BFS
130. Surrounded Regions Solution Medium DFS / BFS / Union Find
131. Palindrome Partitioning Solution Medium Backtracking
133. Clone Graph Solution Medium Graph / DFS / BFS
136. Single Number Solution Easy Bit Manipulation
137. Single Number II Solution Medium Dynamic Programming
138. Copy List with Random Pointer Solution Medium Hash Table / Linked List
139. Word Break Solution Medium Dynamic Programming
140. Word Break II Solution Hard Dynamic Programming
141. Linked List Cycle Solution Easy Linked List / Two Pointers
142. Linked List Cycle II Solution Easy Linked List / Two Pointers
143. Reorder List Solution Medium Linked List
144. Binary Tree Preorder Traversal Solution Medium Tree / Stack
146. LRU Cache Solution Hard Design
147. Insertion Sort List Solution Medium Stack / Design
148. Sort List Solution Medium Stack / Design
149. Max Points on a Line Solution Hard Stack / Design
150. Evaluate Reverse Polish Notation Solution Medium
151. Reverse Words in a String Solution Medium String
152. Maximum Product Subarray Solution Medium String / Two Pointers
153. Find Minimum in Rotated Sorted Array Solution Medium String / Two Pointers
154. Find Minimum in Rotated Sorted Array II Solution Hard String / Two Pointers
155. Min Stack Solution Easy Stack / Design
157. Read N Characters Given Read4 Solution Easy String
158. Read N Characters Given Read4 II - Call multiple times Solution Hard String
159. Longest Substring with At Most Two Distinct Characters Solution Hard String / Two Pointers
160. Intersection of Two Linked Lists Solution Easy String
161. One Edit Distance Solution Medium String
162. Find Peak Element Solution Medium Binary Search
163. Missing Ranges Solution Medium Array
165. Compare Version Numbers Solution Medium
166. Fraction to Recurring Decimal Solution Medium
167. Two Sum II - Input array is sorted Solution Easy
169. Majority Element Solution Easy Array
173. Binary Search Tree Iterator Solution Medium Tree / Stack / Design
179. Largest Number Solution Medium
186. Reverse Words in a String II Solution Easy String
187. Repeated DNA Sequences Solution Medium
188. Best Time to Buy and Sell Stock IV Solution Hard
189. Rotate Array Solution Easy
198. House Robber Solution Easy Dynamic Programming
199. Binary Tree Right Side View Solution Medium
200. Number of Islands Solution Medium BFS / Union Find
201. Bitwise AND of Numbers Range Solution Medium
202. Happy Number Solution Easy
203. Remove Linked List Elements Solution Easy
204. Count Primes Solution Easy
205. Isomorphic Strings Solution Easy Hash Table
206. Reverse Linked List Solution Easy Linked List
207. Course Schedule Solution Medium Graph / BFS / Topological Sort
208. Implement Trie (Prefix Tree) Solution Medium Trie / Design
209. Minimum Size Subarray Sum Solution Medium Array / Two Pointers
210. Course Schedule II Solution Medium Graph / BFS / Topological Sort
212. Word Search II Solution Hard
213. House Robber II Solution Medium
214. Shortest Palindrome Solution Medium String
215. Kth Largest Element in an Array Solution Medium Medium
216. Combination Sum III Solution Medium
217. Contains Duplicate Solution Easy
218. The Skyline Problem Solution Hard
219. Contains Duplicate II Solution Easy
220. Contains Duplicate III Solution Medium
221. Maximal Square Solution Medium Dynamic Programming / BFS
223. Rectangle Area Solution Medium Math
224. Basic Calculator Solution Hard String / Stack
226. Invert Binary Tree Solution Easy Tree
227. Basic Calculator II Solution Medium String
230. Kth Smallest Element in a BST Solution Medium Tree
231. Power of Two Solution Easy Easy
232. Implement Queue using Stacks Solution Easy
233. Number of Digit One Solution Hard
234. Palindrome Linked List Solution Easy Linked List / Two Pointers
235. Lowest Common Ancestor of a Binary Search Tree Solution Easy Tree
236. Lowest Common Ancestor of a Binary Tree Solution Medium Tree
237. Delete Node in a Linked List Solution Easy
238. Product of Array Except Self Solution Medium Array
239. Sliding Window Maximum Solution Hard Heap
240. Search a 2D Matrix II Solution Medium Binary Search / Divide and Conquer
241. Different Ways to Add Parentheses Solution Medium
242. Valid Anagram Solution Easy
243. Shortest Word Distance Solution Easy
246. Strobogrammatic Number Solution Easy Hash Table / Math
247. Strobogrammatic Number II Solution Medium Math / Recursion
249. Group Shifted Strings Solution Medium String
251. Flatten 2D Vector Solution Medium Design
252. Meeting Rooms Solution Easy Sort
253. Meeting Rooms II Solution Medium Heap / Sort
255. Verify Preorder Sequence in Binary Search Tree Solution Medium Medium
256. Paint House Solution Easy
257. Binary Tree Paths Solution Easy Tree / DFS / BFS
259. 3Sum Smaller Solution Medium Array / Two Pointers
261. Graph Valid Tree Solution Medium Graph / BFS / DFS / Union Find
263. Ugly Number Solution Easy Math
264. Ugly Number II Solution Medium Dynamic Programming / Math
265. Paint House II Solution Hard
267. Palindrome Permutation II Solution Medium Backtracking
268. Missing Number Solution Easy Array / Bit Manipulation
269. Alien Dictionary Solution Hard Graph / Topological Sort
270. Closest Binary Search Tree Value Solution Easy Tree / Binary Search
271. Encode and Decode Strings Solution Medium String / Design
272. Closest Binary Search Tree Value II Solution Medium Tree / Stack
273. Integer to English Words Solution Hard String
274. H-Index Solution Medium Sort
276. Paint Fence Solution Easy Dynamic Programming
277. Find the Celebrity Solution Medium Array
278. First Bad Version Solution Easy Binary Search
279. Perfect Squares Solution Medium Math / Dynamic Programming
280. Wiggle Sort Solution Medium Array
281. Zigzag Iterator Solution Medium Design
282. Expression Add Operators Solution Hard Divide and Conquer
283. Move Zeroes Solution Easy Array / Two Pointers
284. Peeking Iterator Solution Medium Design
285. Inorder Successor in BST Solution Medium Tree
286. Walls and Gates Solution Medium BFS
287. Find the Duplicate Number Solution Medium
288. Unique Word Abbreviation Solution Medium
289. Game of Life Solution Medium Array
290. Word Pattern Solution Easy Hash Table
291. Word Pattern II Solution Hard
293. Flip Game Solution Easy String
295. Find Median from Data Stream Solution Hard Heap / Design
296. Best Meeting Point Solution Hard
297. Serialize and Deserialize Binary Tree Solution Hard Tree / Design
298. Binary Tree Longest Consecutive Sequence Solution Medium Tree
299. Bulls and Cows Solution Medium
300. Longest Increasing Subsequence Solution Medium Binary Search / Dynamic Programming
301. Remove Invalid Parentheses Solution Hard Backtracking / DFS / BFS
303. Range Sum Query - Immutable Solution Easy Dynamic Programming
304. Range Sum Query 2D - Immutable Solution Medium Dynamic Programming
305. Number of Islands II Solution Hard Union Find
307. Range Sum Query - Mutable Solution Medium Segment Tree
308. Range Sum Query 2D - Mutable Solution Hard
309. Best Time to Buy and Sell Stock with Cooldown Solution Medium Dynamic Programming
310. Minimum Height Trees Solution Medium BFS/ Graph
311. Sparse Matrix Multiplication Solution Medium Matrix
312. Burst Balloons Solution Hard
313. Super Ugly Number Solution Medium Dynamic Programming / Math
314. Binary Tree Vertical Order Traversal Solution Medium BFS
315. Count of Smaller Numbers After Self Solution Hard Divide and Conqur / Binary Search Tree
317. Shortest Distance from All Buildings Solution Hard BFS
318. Maximum Product of Word Lengths Solution Medium Bit Manipulation
320. Generalized Abbreviation Solution Medium
322. Coin Change Solution Medium
323. Number of Connected Components in an Undirected Graph Solution Medium Graph / Union Find / BFS / DFS
324. Wiggle Sort II Solution Medium
325. Maximum Size Subarray Sum Equals k Solution Medium Array / Hash Table
327. Count of Range Sum Solution Hard
328. Odd Even Linked List Solution Medium
332. Reconstruct Itinerary Solution Medium Graph / DFS
333. Largest BST Subtree Solution Medium Tree
334. Increasing Triplet Subsequence Solution Medium Array
336. Palindrome Pairs Solution Hard Hash Table / String / Trie
337. House Robber III Solution Medium
338. Counting Bits Solution Medium
339. Nested List Weight Sum Solution Easy DFS
340. Longest Substring with At Most K Distinct Characters Solution Hard Hash Table / String
343. Integer Break Solution Medium
344. Reverse String Solution Easy String
345. Reverse Vowels of a String Solution Easy
346. Moving Average from Data Stream Solution Easy
347. Top K Frequent Elements Solution Medium Hash Table / Heap
348. Design Tic-Tac-Toe Solution Medium Design
349. Intersection of Two Arrays Solution Easy
350. Intersection of Two Arrays II Solution Easy
351. Android Unlock Patterns Solution Medium DFS / Dynamic Programming
352. Data Stream as Disjoint Intervals Solution Hard
353. Design Snake Game Solution Medium
354. Russian Doll Envelopes Solution Hard Binary Search / Dynamic Programming
355. Design Twitter Solution Medium Hash Table / Design
357. Count Numbers with Unique Digits Solution Medium
358. Rearrange String k Distance Apart Solution Hard
359. Logger Rate Limiter Solution Easy Hash Table / Design
360. Sort Transformed Array Solution Medium Math / Two Pointers
361. Bomb Enemy Solution Medium Dynamic Programming
362. Design Hit Counter Solution Medium Design
363. Max Sum of Rectangle No Larger Than K Solution Hard
365. Water and Jug Problem Solution Medium
368. Largest Divisible Subset Solution Medium
369. Plus One Linked List Solution Medium Linked List
370. Range Addition Solution Medium
373. Find K Pairs with Smallest Sums Solution Medium Heap
375. Guess Number Higher or Lower II Solution Medium
377. Combination Sum IV Solution Medium Dynamic Programming
378. Kth Smallest Element in a Sorted Matrix Solution Medium Binary Search / Heap
380. Insert Delete GetRandom O(1) Solution Medium Hash Table / Design
382. Linked List Random Node Solution Medium Reservoir Sampling
383. Ransom Note Solution Easy
384. Shuffle an Array Solution Medium
386. Lexicographical Numbers Solution Medium
387. First Unique Character in a String Solution Easy
392. Is Subsequence Solution Medium
393. UTF-8 Validation Solution Medium
394. Decode String Solution Medium String / DFS
396. Rotate Function Solution Medium
399. Evaluate Division Solution Medium Graph
403. Frog Jump Solution Hard
405. Convert a Number to Hexadecimal Solution Easy
406. Queue Reconstruction by Height Solution Medium
407. Trapping Rain Water II Solution Medium
408. Valid Word Abbreviation Solution Easy String
409. Longest Palindrome Solution Easy Hash Table
410. Split Array Largest Sum Solution Hard
412. Fizz Buzz Solution Easy Array
416. Partition Equal Subset Sum Solution Medium Dynamic Programming
417. Pacific Atlantic Water Flow Solution Medium DFS / BFS
418. Sentence Screen Fitting Solution Medium Dynamic Programming
433. Minimum Genetic Mutation Solution Medium BFS
435. Non-overlapping Intervals Solution Medium Greedy
436. Find Right Interval Solution Medium Array / Binary Search
438. Find All Anagrams in a String Solution Easy Hash Table
441. Arranging Coins Solution Easy Math
444. Sequence Reconstruction Solution Medium Graph / Topological Sort
450. Delete Node in a BST Solution Medium Tree
451. Sort Characters By Frequency Solution Medium Hash Table / Heap
461. Hamming Distance Solution Easy Bit Manipulation
467. Unique Substrings in Wraparound String Solution Medium Dynamic Programming
473. Matchsticks to Square Solution Medium DFS
477. Total Hamming Distance Solution Medium Bit Manipulation
482. License Key Formatting Solution Medium Array
484. Find Permutation Solution Medium Greedy
486. Predict the Winner Solution Medium Dynamic Programming / Minimax
487. Max Consecutive Ones II Solution Medium Two Pointers
489. Robot Room Cleaner Solution Hard DFS
490. The Maze Solution Medium BFS / DFS
494. Target Sum Solution Medium Backtracking
496. Next Greater Element I Solution Easy Stack
498. Diagonal Traverse Solution Medium Matrix
499. The Maze III Solution Hard DFS / BFS