GithubHelp home page GithubHelp logo

leetcode-1's Introduction

For Non leetcode questions, click here

non leetcode tests

LeetCode Questions And Answers

# question Answer level
001 two sum Java - without hashMap
Java space O(n) time O(n) - with HashMap
Java - space O(1) time O(n*2)
easy
002 add two numbers Java - O(n)
Java - O(n) better code
medium
003 Longest Substring Without Repeating Characters Java - sliding window
Java - another
medium
004 median of two sorted arrays Java O(log(m+n)) hard
005 longest palindrome substring Java O(n^3)
Java O(n^2) space O(n^2)
Java O(n^2) space O(1)
medium
006 zigzag conversion Java easy
007 reverse int Java
Java - Better
easy
008 string to integer Java
Java - AutoMata
easy
009 palindrome number Java easy
010 regular expression Java O(N^2) DP hard
011 container with the most water Java space O(1) time O(n) medium
012 Intger to roman Java medium
013 Roman to Integer C++
Java
easy
014 longest common prefix Java
Java better solution
Java - divide and conqure
easy
015 3 sum Java medium
016 3sum closest Java medium
017 letter combination of phone number Java - recursive
Java - DP
Java - backtracking
medium
018 4 sum Java medium
019 remove Nth node from the end of the list Java - O(n) easy
020 valid parentheses Java - solution 1 - stack
Java - Array as stack -- much faster
easy
021 merge two sorted linked list Java - iter 2
Java - iter 3
Java - Iter
Java - recurrsive
Java - right but no good solution
C++
easy
022 generate parentheses Java - DFS hard
023 merge k sorted listnodes Java - merge sort hard
024 swap nodes in pairs Java - Iter
Java - Recurr
medium
025 reverse nodes in N group Java - O(n)
Java - recursive
hard
026 remove duplicates from sorted array Java - solution 1
Java - solution 2
easy
027 remove element Java
Java - right, but not perfect coding
easy
028 implement strStr Java - KMP O(n)
Java - brute force
easy
029 divide integer Java - iterative
Java - recursive
medium
030 Substring with Concatenation of All Word Java hard
031 Next Permutation Java medium
032 Longest valid parenthesis Java-stack hard
033 Search in Rotated Sorted Array Java hard
034 search for a range Java medium
035 Search Insert Position C++
Java - O(n)
Java - O(logn)
easy
036 valid sudoku Java
Java - O(n*n)
easy
037 sudoku solver Java - backtracking hard
038 count and say Java easy
039 combination sum Java - backtracking Optimized
Java - Not Optimized
medium
040 combination sum II Java medium
041 find missing positive Java - O(n)
Java - O(n)
hard
042 trapping the rain water Java - time O(n^2) span O(1)
Java - DP time O(3n) span O(n)
Java - two pointer time O(n) space O(1)
Java - stack time O(n) space O(n)
hard
043 multiply strings Java
Java - better
medium
044 Wildcard Matching Java hard
045 Jump Game II Java - Greedy O(n)
Java - DP O(n^2)
hard
046 Permuation Java - backtracking medium
047 Permutation II Java medium
048 rotate image Java - In place medium
049 group anagrams Java
Java - sort str
medium
050 power(x,n) Java
Java
medium
051 N-Queens Java - Backtracking hard
052 N-queens II Java hard
053 max subarray Java - space O(1)
Java - space O(n)
C++ D&C
medium
054 Spiral Matrix Java medium
055 jump game Java medium
056 merge interval Java hard
057 insert interval Java hard
058 length of last word Java
Java - From back
easy
059 Spiral Matrix II Java medium
060 next permutation Java medium
061 rotate list Java medium
062 unique path Java - space O(m*n)
Java - space O(n)
Java - space O(1) math
C++
medium
063 unique path II Java medium
064 minimum path sum Java - In place
Java - O(mn)
Java - O(n)
C++
medium
065 valid number Java hard
066 plus one java
Java - another
easy
067 add binary Java easy
068 text justification Java hard
069 sqrt(x) Java - newton
Java - binary search
easy
070 climb stairs Java - recursive
Java - DP O(n)
Java - DP O(1)
C++
easy
071 simplify path java medium
072 edit distance Java - O(m*n) hard
073 set matrix zeros Java medium
074 search a 2D ma"trix Java
Java - binary Search
medium
075 sort colors Java
C - two pointers
C - count&replace
medium
076 minimum window substring Java - two pointers, O(n) hard
077 combinations Java - backtracking medium
078 subset Java medium
079 word search Java medium
080 remove duplicate from sorted array II Java medium
081 search in rotated array II Java medium
082 remove duplicates from sorted list II Java - O(n) medium
083 remove duplicates from sorted list Java - Ugly
Java - Pretty
C++
easy
084 largest rectangle in histogram Java - O(n)
Java - Stack
Java - divide and conqure
hard
085 maximal rectangle Java hard
086 partition list java medium
087 scramble string Java -recursive hard
088 merge sorted array Java easy
089 gray code Java
C
medium
090 subsets II Java medium
091 decode ways Java - DP O(n)
Java - DP O(1)
medium
092 reverse linked list II Java medium
093 Restore IP Address Java - backtracking medium
094 binary tree inorder traversal Java - recur
Java - iter
Java - Morris
C++ iter
C++ recursion
medium
095 unique binary search tree II Java medium
096 Unique Binary Search Trees C++
Java - DP
Medium
097 interleaving string Java - DP hard
098 validate binary search tree Java - recursive inorder
Java - recursive
Java - iterative inorder
Java - recursive with boundary
medium
099 recover binary search tree Java hard
100 Same Tree C++
Java - recursive
Java - iterative
easy
101 symmetric tree Java - iter
Java -recur
C++
easy
102 binary tree level order traversal Java - stack
Java - queue
Java - recursive
easy
103 binary tree zigzag level order traversal Java medium
104 Maximum Depth of Binary Tree C++
Java
Java - iterative
Java - DFS iter
easy
105 construct binary tree from inorder and preorder traversal Java medium
106 construct binary tree from inorder and postorder traversal Java medium
107 binary tree level order traversal II Java
C++
easy
108 convert sorted array to binary search tree Java medium
109 convert sorted list to binary search tree Java - cheating, use array
Java
medium
110 balanced tree Java - O(n^2)
Java -O(n)
C++
easy
111 minimum depth tree Java - BFS
Java - DFS
easy
112 path sum Java - recur
Java - queue
Java - stack
easy
113 path sum II Java - recursive
Java - backtracking
medium
114 flatten binary tree to linked list Java - recursive
Java - iterative
medium
115 distinct subsequences Java - DP, O(m*n)
Java - DP O(N) space
hard
116 Populate Next Right Ptrs In Each Node C++
Java
Java - O(1) space
medium
117 populate next right pointer in each node II Java - space O(N)
Java - space O(1)
hard
118 pascal triangle Java - recurrsive
Java - Iterative
Java - better recursive
easy
119 pascal triangle II Java space O(n)
Java - new solution
easy
120 triangle Java
Java - Bottom Up
medium
121 best time to buy and sell stock Java
Java - improve
Java - space O(1) time O(n)
medium
122 best time buy/sell stock II Java - time O(n), space O(n)
C++
medium
123 best time to buy and sell stock III Java - Space O(n)
Java Space O(1)
medium
124 binary tree max path sum Java hard
125 valid palindrome Java
Java - regex
easy
126 word ladder II Java hard
127 word ladder Java
Java - graph
medium
128 Longest Consecutive Sequence Java
Java
hard
129 sum root to leaf numbers Java - 1
Java - 2
medium
130 surrounded regions Java
Java - union find
medium
131 Palindrome partitioning Java - backtracking medium
132 Palindrome Partition II Java hard
133 clone graph Java - BFS
Java - DFS
medium
134 Gas Station Java medium
135 candy Java - space O(3N), time O(3N)
Java - space O(1), time O(N)
hard
136 single number Java - time O(n) space O(1)
Java - HashSet
C++
medium
137 Single Number II C++
Java
Java O(n)
medium
138 copy list with random pointer Java - wrong
Java - O(n) time O(1) space
hard
139 word break Java medium
140 word break II Java -DP hard
141 Linked List Cycle C++
Java
medium
142 linked list cycle II Java medium
143 reorder list Java medium
144 binary tree preorder traversal Java - recurrsive bad
Java -recursive good
Java -iter
Java - Morris
C++ iter
C++ recursive
medium
145 binary tree post order traversal Java - recurr hard
146 LRU cache Java hard
147 insertion sort list Java - O(n^2) medium
148 sort list Java medium
149 Max Points On a Line Java hard
150 evaluate reverse polish notation Java
Java - Better OOP
medium
151 reverse words in string Java medium
152 maximum prod subarray Java - DP
Java - two arrays
medium
153 find min from rotated sorted array Java
Java - better
medium
154 find min from rotated sorted array Java hard
155 min stack Java
Java - Single Stack
easy
156 binary tree upside down Java - recursive
Java - Iterative
medium
157 read N chars given read4 Java - solution easy
158 read N chars given read4 II Java - solution 1
Java - solution 2
hard
159 longest substring with at most two distinct char Java - HashMap
Java - Array
hard
160 intersection of two linkedlists Java - 1
Java - 2
easy
161 one edit distance Java - solution1
Java - Solution2
medium
162 find peak ele Java -O(n)
Java - O(log(n))
medium
163 missing ranges Java - O(n) medium
164 Maximum gap Java - nlog(n)
Java -O(n) bucket sort
hard
165 compare version Java easy
166 Fraction to recurring decimal Java medium
167 two sum II Java - two pointers easy
168 excel sheet column title Java easy
169 majority element Java - HashMap
Java - sort
Java - space O(1)
Java - Bit manipulation
C++
easy
170 two sum III Java - add O(n) find O(1)
Java - add O(1) find O(n)
easy
171 Excel Sheet Column Number C++
Java
easy
172 factorial trailing zeros Java - log(n) easy
173 binary search tree iterator Java medium
174 dungeon game Java - DP, memorization hard
175 combine two tables MySQL - left join easy
176 second highest salary MySQL - Offset easy
177 Nth highest salary MySQL medium
178 salary rank MySQL
179 largest number Java medium
180 consecutive numbers MySQL medium
181 Employees Earning More Than Their Managers MySQL easy
182 duplicate email MySQL easy
183 customoer who never order MySQL easy
184 highest department salary MySQL - Join & In medium
185 department top three salaries MySQL hard
186 reverse words in string II Java - Solution medium
187 repeated DNA sequence Java
Java - Rolling Hash
medium
188 best time to buy and sell stock IV Java hard
189 rotate array Java - reverse O(3n)
Java - O(n)
easy
190 reverse bits Java - 1
Java - 2
Java - better solution
easy
191 Number of 1 Bits C++
Java - 1
Java - 2
medium
192 word frequency bash - tr, sort, uniq, awk easy
193 valid phone number bash - grep easy
194 transpose file Bash medium
195 tenth line Bash easy
196 delete dup emails MySQL easy
197 rise temprature MySQL easy
198 house robber Java DP
Java better code
C++
easy
199 binary tree right view Java - BFS
Java - recursive
medium
200 number of islands Java - DFS medium
201 bitwise AND of range of nums Java - brute force
Java - bitwise AND
medium
202 happy number Java
C++
easy
203 remove element from linked list Java
204 count primes Java easy
205 isomorphic string Java
Java - array
easy
206 reverse link list Java - recursive
Java - Iterative
C++ recursive
C++ stack
(C++ iterative)
easy
207 course schedule Java - DFS
Java - DFS with edge classification
medium
208 Implement Trie Java medium
209 minimum size subarray sum Java - O(n^2)
Java - O(n)
Java -O(nlogn)
medium
210 course schedule II Java - topological sort medium
211 add and search word - data structure Java - Trie medium
212 word search II Java hard
213 house robber II Java - DP medium
214 shortest palindrome Java - O(n^2)
Java - O(1/4*n^2)
hard
215 kth largest element in an array Java - quick selection
Java - sort
Java - priority queue
medium
216 combination sum III Java - Backtracking medium
217 Contains Duplicate C++
Java - hash set
Java - insertion sort
easy
219 contains duplicate II Java easy
221 maximum square Java
Java - Better DP
medium
222 count complete tree nodes Java - recursive medium
223 rectangle area Java easy
224 basic calculator Java hard
225 implement stack using queue Java - two queues push O(1) pop O(n)
Java - two queue push O(n) pop O(1)
Java - one queue
easy
226 Invert Binary Tree C++
Java - recursive
Java - Iterative
C - recursive
easy
227 basic calculator II Java medium
228 summary ranges Java easy
229 majority element II Java medium
230 kth element in BST Java - recursive
Java - iterative
Java - to array
medium
231 Power Of Two C++
Java
easy
232 implement queue using stack Java - two stacks I
Java - two stacks II
Java - one stack
easy
233 number of digit one Java hard
234 palindrome linked list Java easy
235 Lowest Common Ancestor of a Binary Search Tree C++
Java - recursive
Java - iterative
easy
236 Lowest ancestor of a binary tree Java - recursive O(n)
Java - iterative
medium
237 Delete Node in a Linked List C++
Java
easy
238 product Array Except Itself Java - time O(n) space O(1)
C++
medium
239 sliding window maximum Java - brute force
Java - deque
hard
240 search 2D matrix Java - O(m*log(n))
Java - O(m+n)
easy
241 different wayts to add parenthese Java
Java - divide and conqure with memo
medium
242 valid anagram Java - cheating - space O(1)
Java - space O(1)
Java - space O(26) - array
C++
easy
243 shortest word distance Java - HashMap
Java - Array
easy
244 shortest word distance II Java medium
245 shortest word distance III Java - O(n) medium
246 strobogrammatic number Java - HashMap
Java - Array
easy
247 strobogrammatic number II Java - bfs
Java - dfs
medium
249 group shifted strings Java - hashMap
Java - more comlicated
medium
250 count uni value trees Java - Post Order medium
251 flattern 2D vector Java - use pointer
Java - use iterator
medium
252 meeting rooms Java - quick sort
Java - comparator
easy
253 meeting room II Java medium
256 paint house Java - DP easy
257 binary tree path Java - Recursive
Java - recursive with memorization
Java - backtracking
easy
258 Add Digits C++
Java - iterative
Java recursive
Java digit root O(1)
C
easy
259 3 sum smaller Java - brute force
Java - O(n^2)
Java - O(n^2* log(n)
260 single number III Java - space O(1) ugly
Java - space O(1) pretty
C++
medium
263 ugly number Java
C++
easy
264 ugly number II Java - DP medium
266 palindrome permutation Java - HashSet easy
268 missing number Java - time O(n), space O(1)
Java - better coding style
Java - bitwise
C++
medium
269 alien dictionary Java - Kahn's algo topo sort hard
270 closest binary search tree Java - recursive
Java - iterative
easy
271 encode decode strings Java - with deliminator medium
274 H-index Java - O(n)
Java - O(nlogn)
medium
275 H-Index II Java - O(log(n)) medium
276 paint fence Java - recursive
Java - DP
easy
277 find celebrity Java - brute force O(n^2)
Java - O(3n)
Java - O(2n)
medium
278 first bad version Java easy
279 perfect square Java - DP
Java - BFS
medium
280 wiggle sort java - O(n) greedy medium
281 zigzag iterator Java - Queue medium
282 Expression Add Operator Java hard
283 move zeros Java O(n)
Java - O(n) better sol
C++
easy
284 peeking iterator Java medium
287 find the duplicate number Java - bloom filter
Java - invert in place
Java - tortoise and hare
hard
288 unique word abbr Java - HashMap medium
289 game of life Java O(n)
Java O(1)
Java O(1)
medium
290 word pattern Java easy
292 Nim Game Java
C++
C
easy
293 flip game Java - O(n) easy
295 find medium from data stream Java - binary search
Java - priority queue
hard
297 Serialize And Deserialize Tree Java - DFS preorder
Java - BFS
hard
299 bulls and cows Java easy
300 Longest Increasing Subsequence Java
Java - brute force
meidum
301 remove invalid parentheses Java -BFS
Java - DFS
hard
302 smallest rectangle enclosing black pixels Java - DFS hard
303 range sum query Java easy
304 Range Sum Query 2D - Immutable Java - DP medium
306 additive number Java hard
307 range sum query mutable Java - Binary Index Tree medium
308 range sum query - 2D mutable Java - Binary Index Tree hard
312 burst ballons Java - DP hard
313 super ugly number Java medium
314 binary tree vertical order traversal Java medium
315 count of smaller num after self Java hard
316 remove dup letters Java -array
Java - hashMap
hard
318 max product of the word length Java medium
319 bulb switcher Java - solution 1 slow
Java - solution 2 fast
medium
320 generalized abbr Java - HashSet
Java - List
Java - DFS
medium
322 coin change Java - DP medium
323 number of connected compnents in an undirected graph Java - bfs
Java - union find
medium
325 maximum size subarray sum equals k Java - O(n) medium
326 power of three Java - recur
Java - iter
C++
easy
328 odd even linked list Java solution
C++
easy
329 longest path in matrix Java hard
330 patching array Java
Java - simplified
331 verify preorder serialization of a binary tree Java - node count
Java - stack
medium
332 recontruct itinerary Java medium
334 increasing triplet subsequence Java- O(n) medium
336 Palindrome Pairs Java - O(n^2*m)
Java - Trie
hard
337 house robber III Java
C
medium
338 count bits Java - O(32 * num)
Java - O(1)
Java - better O(1)
C
medium
339 nested list weight sum Java - recursive easy
341 flatten nested list iterator Java
Java - lazy initialization
medium
342 power of four Java - 1
Java - 2
Java - 3
C
easy
343 integer break Java
C
medium
344 reverse string Java
C
easy
345 reverse vowels of str Java
C
easy
346 moving average from data stream Java - solution easy
347 top k frequent elements Java - Priority Queue medium
348 design tic tac toe Java - O(n)
Java - O(1)
medium
349 intersection of two arrays Java - sort and compare
Java - BitSet
Java - sort one and hashset
easy
350 intersection of two arrays Java - two pointer easy
351 android unlock pattern Java - backtracking medium
352 data stream as disjoint intervals Java hard
353 design snake game Java - 2D
Java - 1D
medium
357 count numbers with unique digits Java - DP medium
359 logger ratelimiter Java - HashMap
Java - Queue
easy
362 design hit counter Java - Queue
Java - Array
medium
366 find leaves of binary tree Java - backtracking
Java - remove node
medium
367 valid perfect square Java - binary search medium
368 largest divisible subset Java
Java - optimized
medium
369 plus one linked list Java - reverse
Java - recursive
Java - two pointer
medium
370 range addition Java - hashMap
Java - range caching
medium
371 sum of integer Java - Solution 1
Java - better Solution
easy
375 guess num high low II Java - recursive
Java - recursive with memo
Java - better recursive with memo
medium
377 combination sum IV Java - recursive
Java - recursive with memo
Java - DP
medium
379 design phone diretory Java medium
380 insert delete getRandom O(1) Java medium
383 ransom note Java - O(n) easy
387 first unique char in string Java - HashSet
Java - O(n) array
Java - O(n) concise
easy
388 longest absolute file path Java - Stack medium
389 find the difference Java easy
393 UTF-8 validation Java medium
396 rotate func java - n^2
Java - O(n)
easy
397 integer replacement Java - 1 medium
401 binary watch Java easy
402 remove k digits Java - Stack medium
404 sum of leaves Java - recursive medium
405 convert number to hex Java - 1
Java - 2
easy
408 validate word abbr Java easy
409 longest palindrome Java - hashMap
Java - array
easy
410 split array largest sum Java - binary search hard
415 add string Java easy
416 partition equal subset sum Java - DP medium
422 valid word square Java - space O(n)
Java - space O(1)
easy
439 ternary expression parser Java - use str replace
Java - use stack
Java - dfs
medium
448 Find All Numbers Disappeared in an Array Java - O(n)
Java - O(1)
easy
445 add two numbers II Java - reverse list
Java - stack
medium
450 delete node from bst Java - recursive medium
451 sort char by freq Java - PriorityQueue medium
456 find 132 pattern Java - O(n^3)
Java - O(n^2)
Java - O(n)
medium
459 Repeated Substring Pattern Java easy
461 hamming distance Java - Solution 1
Java - alternative
easy
463 island perimeter Java easy
476 number complement Java - Solution 1
Java - Java API
easy
482 license key formatting Java - Stack
Java - no stack
medium
490 the maze Java - DFS
Java - BFS
medium
494 target sum Java - brute force
Java - brute force with memo
Java - DP
Java - DP O(n)
medium
496 next greater element Java - O(m*n)
Java - O(m*n)
Java - O(n)
easy
500 keyboard word Java easy
503 next greater element II brute force - O(n^2) O(2n)
brute force O(n^2) O(n)
Java - Stack
medium
515 find largest in each tree row Java - BFS
Java - DFS
medium
513 find bottom left tree Java - BFS
Java - Recursive
medium
520 detect capital Java
Java use char-> int
easy
529 mine sweeper Java medium
530 find minimum abs diff in bst Java - traversal & sort
Java - inorder
easy
531 lonely pixel I Java - O(n)
Java - O(1)
medium
532 k diff pairs in array Java - HashMap easy
536 construct binary tree from str Java medium
537 multiply complex num Java easy
538 convert bst to greater tree Java medium
543 diameter of binary tree Java - recursive easy
544 Output Contest Matches Java - Solution medium
544 Output Contest Matches Java - Solution medium
545 boundary of binary tree Java - Solution hard
547 friend circle Java - union find medium
551 student attendance record I Java - O(n)
Java - regex
easy
553 optimal division Java - Math medium
560 subarray sum equals k Java - brute force
Java - store the sum O(n^2) O(n)
Java - O(n^2) O(1)
Java - HashMap
medium
561 array partition I Java - Quick Sort
Java - array
easy
570 manager with at least 5 direct reporters Mysql easy
572 subtree of another tree Java - preorder
Java - dfs
easy
581 shortest unsorted continuous subarray Java - space O(n)
Java - span O(1)
easy
582 kill process Java - DFS recursive
Java - DFS stack
Java - BFS
medium
583 delete operation for 2 strings Java - longest commen str
Java - longest with memorization
Java - DP longest common
Java - DP
medium
595 big countries SQL easy
604 design compressed string iterator Java - O(m)
Java - O(#distint char)
medium
605 can place flower Java - DP easy
606 construct str from binary tree Java - recursive
Java - iterative
Java - recursive another
medium
609 find duplicated file in the system Java - HashMap medium
611 valid triangle number Java - O(n^2) medium
613 shortest distance in line MySQL easy
617 merge two binary tree Java - recursive
Java - iterative
easy
627 swap salary MySQL easy
635 design log storage system Java - list
Java - TreeMap
medium
637 average of levels in binary tree Java - BFS easy
639 decode ways II Java - recursive
Java - DP
hard
640 solve the equation Java - regex medium
643 max average subarray I Java easy
645 set mismatch Java - Set
Java - flip array ele
easy
646 max len of pair chain Java - sort medium
653 two sum IV Java - hashset
Java - traversal
easy
657 Judge Route Circle Java easy
661 image smoother Java easy
662 max width of binary tree Java - BFS medium
663 Equal Tree Partition Java - dfs medium
669 trim bst Java - recursive easy

leetcode-1's People

Contributors

curtisai avatar fandan-nyc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.