Skip to content

Taiwolskit/leetcode

Repository files navigation

LeetCode Solution

Cracking the LeetCode with multiple programming languages How do I choose the solution?

  1. Choose the solution with the best time complexity and space complexity from the official solutions.
  2. If the best time complexity and space complexity solutions are different, choose the best solution from each one.
  3. If there are no official solutions, choose the best solution from the submissions for each language. These best solutions are not necessarily the ones with the best time complexity and space complexity but instead are selected based on the readability of the solution. Overly complex and tricky solutions will not be selected.

Algorithms

Number Title Difficulty Solution Golang JavaScript Kotlin PHP Python Rust Swift
1 Two Sum Easy
2 Add Two Numbers Medium
3 Longest Substring Without Repeating Characters Medium
4 Median of Two Sorted Arrays Hard
5 Longest Palindromic Substring Medium
6 ZigZag Conversion Medium
7 Reverse Integer Easy
8 String to Integer (atoi) Medium
9 Palindrome Number Easy
10 Regular Expression Matching Hard
11 Container With Most Water Medium
12 Integer to Roman Medium
13 Roman to Integer Easy
14 Longest Common Prefix Easy
15 3Sum Medium
16 3Sum Closest Medium
17 Letter Combinations of a Phone Number Medium
18 4Sum Medium
19 Remove Nth Node From End of List Medium
20 Valid Parentheses Easy
21 Merge Two Sorted Lists Easy
22 Generate Parentheses Medium
23 Merge k Sorted Lists Hard
24 Swap Nodes in Pairs Medium
25 Reverse Nodes in k-Group Hard
26 Remove Duplicates from Sorted Array Easy
27 Remove Element Easy
28 Implement strStr() Easy
29 Divide Two Integers Medium
30 Substring with Concatenation of All Words Hard
31 Next Permutation Medium
32 Longest Valid Parentheses Hard
39 Combination Sum Medium
46 Permutations Medium
54 Spiral Matrix Medium
59 Spiral Matrix II Medium
61 Rotate List Medium
66 Plus One Easy
67 Add Binary Easy
70 Climbing Stairs Easy
74 Search a 2D Matrix Medium
75 Sort Colors Medium
78 Subsets Medium
79 Word Search Medium
81 Search in Rotated Sorted Array II Medium
88 Merge Sorted Array Easy
94 Binary Tree Inorder Traversal Medium
99 Recover Binary Search Tree Medium
104 Maximum Depth of Binary Tree Easy
115 Distinct Subsequences Hard
118 Pascal's Triangle Easy
119 Pascal's Triangle II Easy
121 Best Time to Buy and Sell Stock Easy
127 Word Ladder Hard
129 Sum Root to Leaf Numbers Medium
130 Surrounded Regions Medium
134 Gas Station Medium
136 Single Number Easy
138 Copy List with Random Pointer Medium
141 Linked List Cycle Easy
142 Linked List Cycle II Medium
147 Insertion Sort List Medium
151 Reverse Words in a String Medium
160 Intersection of Two Linked Lists Easy
167 Two Sum II - Input Array Is Sorted Medium
173 Binary Search Tree Iterator Medium
189 Rotate Array Medium
198 House Robber Medium
203 Remove Linked List Elements Easy
206 Reverse Linked List Easy
209 Minimum Size Subarray Sum Medium
230 Kth Smallest Element in a BST Medium
234 Palindrome Linked List Easy
237 Delete Node in a Linked List Easy
258 Add Digits Easy
279 Perfect Squares Medium
282 Expression Add Operators Hard
283 Move Zeroes Easy
284 Peeking Iterator Medium
287 Find the Duplicate Number Medium
289 Game of Life Medium
290 Word Pattern Easy
309 Best Time to Buy and Sell Stock with Cooldown Medium
312 Burst Balloons Hard
328 Odd Even Linked List Medium
344 Reverse String Easy
347 Top K Frequent Elements Medium
387 First Unique Character in a String Easy
389 Find the Difference Easy
402 Remove K Digits Medium
410 Split Array Largest Sum Hard
412 Fizz Buzz Easy
414 Third Maximum Number Easy
430 Flatten a Multilevel Doubly Linked List Medium
442 Find All Duplicates in an Array Medium
448 Find All Numbers Disappeared in an Array Easy
452 Minimum Number of Arrows to Burst Balloons Medium
463 Island Perimeter Easy
485 Max Consecutive Ones Easy
487 Max Consecutive Ones II Medium
498 Diagonal Traverse Medium
504 Base 7 Easy
520 Detect Capital Easy
532 K-diff Pairs in an Array Medium
538 Convert BST to Greater Tree Medium
557 Reverse Words in a String III Easy
560 Subarray Sum Equals K Medium
561 Array Partition I Easy
567 Permutation in String Medium
605 Can Place Flowers Easy
669 Trim a Binary Search Tree Medium
680 Valid Palindrome II Easy
682 Baseball Game Easy
698 Partition to K Equal Sum Subsets Medium
700 Search in a Binary Search Tree Easy
701 Insert into a Binary Search Tree Medium
703 Kth Largest Element in a Stream Easy
705 Design HashSet Easy
707 Design Linked List Medium
708 Insert into a Sorted Circular Linked List Medium
724 Find Pivot Index Easy
725 Split Linked List in Parts Medium
740 Delete and Earn Medium
746 Min Cost Climbing Stairs Easy
747 Largest Number At Least Twice of Others Easy
763 Partition Labels Medium
764 Largest Plus Sign Medium
782 Transform to Chessboard Hard
848 Shifting Letters Medium
875 Koko Eating Bananas Medium
876 Middle of the Linked List Easy
881 Boats to Save People Medium
882 Reachable Nodes In Subdivided Graph Hard
897 Increasing Order Search Tree Easy
905 Sort Array By Parity Easy
917 Reverse Only Letters Easy
922 Sort Array By Parity II Easy
923 3Sum With Multiplicity Medium
929 Unique Email Addresses Easy
941 Valid Mountain Array Easy
977 Squares of a Sorted Array Easy
978 Longest Turbulent Subarray Medium
980 Unique Paths III Hard
991 Broken Calculator Medium
993 Cousins in Binary Tree Easy
1007 Minimum Domino Rotations For Equal Row Medium
1008 Construct Binary Search Tree from Preorder Traversal Medium
1029 Two City Scheduling Medium
1046 Last Stone Weight Easy
1051 Height Checker Easy
1089 Duplicate Zeros Easy
1099 Two Sum Less Than K Easy
1143 Longest Common Subsequence Medium
1189 Maximum Number of Balloons Easy
1239 Maximum Length of a Concatenated String with Unique Characters Medium
1260 Shift 2D Grid Easy
1275 Find Winner on a Tic Tac Toe Game Easy
1293 Shortest Path in a Grid with Obstacles Elimination Hard
1295 Find Numbers with Even Number of Digits Easy
1299 Replace Elements with Greatest Element on Right Side Easy
1328 Break a Palindrome Medium
1342 Number of Steps to Reduce a Number to Zero Easy
1346 Check If N and Its Double Exist Easy
1480 Running Sum of 1d Array Easy
1629 Slowest Key Easy
1663 Smallest String With A Given Numeric Value Medium
1672 Richest Customer Wealth Easy
1991 Find the Middle Index in Array Easy

Concurrency

Number Title Difficulty Solution Python
1114 Print in Order Easy
1115 Print FooBar Alternately Medium
1116 Print Zero Even Odd Medium
1117 Building H2O Medium
1188 Design Bounded Blocking Queue Medium
1195 Fizz Buzz Multithreaded Medium
1226 The Dining Philosophers Medium
1242 Web Crawler Multithreaded Medium
1279 Traffic Light Controlled Intersection Easy

Database

Number Title Difficulty Solution MySQL
175 Combine Two Tables Easy
176 Second Highest Salary Medium
177 Nth Highest Salary Medium
178 Rank Scores Medium
180 Consecutive Numbers Medium
181 Employees Earning More Than Their Managers Easy
182 Duplicate Emails Easy
183 Customers Who Never Order Easy
184 Department Highest Salary Medium
185 Department Top Three Salaries Hard
196 Delete Duplicate Emails Easy
197 Rising Temperature Easy
262 Trips and Users Hard
511 Game Play Analysis I Easy
584 Find Customer Referee Easy
586 Customer Placing the Largest Number of Orders Easy
595 Big Countries Easy
596 Classes More Than 5 Students Easy
601 Human Traffic of Stadium Hard
607 Sales Person Easy
620 Not Boring Movies Easy
626 Exchange Seats Medium
627 Swap Salary Easy
1050 Actors and Directors Who Cooperated At Least Three Times Easy
1148 Article Views I Easy
1158 Market Analysis I Medium
1179 Reformat Department Table Easy
1407 Top Travellers Easy
1581 Customer Who Visited but Did Not Make Any Transactions Easy
1693 Daily Leads and Partners Easy
1729 Find Followers Count Easy
1757 Recyclable and Low Fat Products Easy
1873 Calculate Special Bonus Easy
1965 Employees With Missing Information Easy

Shell

Number Title Difficulty Solution Bash
192 Word Frequency Medium
193 Valid Phone Numbers Easy
194 Transpose File Medium
195 Tenth Line Easy