Code Monkey home page Code Monkey logo

leetcode-solutions's Introduction

LeetCode Solutions

Build Status

Introduction

LeetCode is a very good website to sharpen your programming/problem-solving skills. Of course, not all solutions here are optimal and your suggestions and contributions are welcomed.

Contents

# Title Solution Difficulty
1 Two Sum Java,Python Easy
2 Add Two Numbers Java,Python Medium
3 Longest Substring Without Repeating Characters Java,Python Medium
7 Reverse Integer Java Easy
8 String to Integer (atoi) Java,Python Medium
9 Palindrome Number Java Easy
11 Container With Most Water Java,Python Medium
12 Integer to Roman Java Medium
13 Roman to Integer Java Easy
14 Longest Common Prefix Java Easy
15 3Sum Java,Python Medium
16 3Sum Closest Java Medium
17 Letter Combinations of a Phone Number Java Medium
19 Remove Nth Node From End of List Java Easy
20 Valid Parentheses Java Easy
21 Merge Two Sorted Lists Java,Python Easy
22 Generate Parentheses Java Medium
23 Merge k Sorted Lists Python Medium
24 Swap Nodes in Pairs Java Medium
25 Reverse Nodes in k-Group Python Medium
26 Remove Duplicates from Sorted Array Java Easy
27 Remove Element Java Easy
28 Implement strStr() Java Easy
29 Divide Two Integers Python Medium
31 Next Permutation Python Medium
32 Longest Valid Parentheses Python Hard
33 Search in Rotated Sorted Array Java,Python Medium
34 Find First and Last Position of Element in Sorted Array Python Medium
35 Search Insert Position Java Medium
36 Valid Sudoku Java Easy
38 Count and Say Java Easy
39 Combination Sum Java,Python Medium
40 Combination Sum II Python Hard
41 First Missing Positive Python Medium
42 Trapping Rain Water Python Hard
43 Multiply Strings Java Medium
46 Permutations Java,Python Medium
47 Permutations II Python Medium
48 Rotate Image Python Medium
49 Group Anagrams Python Medium
50 Pow(x, n) Java Medium
53 Maximum Subarray Java,Python Medium
54 Spiral Matrix Java,Python Medium
55 Jump Game Java Medium
56 Merge Intervals Python Medium
56 Insert Interval Python Hard
58 Length of Last Word Java Easy
59 Spiral Matrix II Python Medium
60 Permutation Sequence Python Medium
61 Rotate List Java,Python Medium
62 Unique Paths Python Medium
63 Unique Paths II Python Medium
64 Minimum Path Sum Python Medium
66 Plus One Java Easy
67 Add Binary Java Easy
69 Sqrt(x) C++,Python Easy
70 Climbing Stairs Java Easy
71 Simplify Path Python Medium
72 Edit Distance Java,C++ Hard
73 Set Matrix Zeroes Java Medium
74 Search a 2D Matrix Java Medium
75 Sort Colors Java,Python Medium
76 Minimum Window Substring Python Hard
77 Combinations Java,Python Medium
78 Subsets Python Medium
79 Word Search Python Medium
80 Remove Duplicates from Sorted Array II Java Medium
81 Search in Rotated Sorted Array II Python Medium
82 Remove Duplicates from Sorted List II C++,Java,Python Medium
83 Remove Duplicates from Sorted List Java Easy
84 Largest Rectangle in Histogram Python Hard
85 Maximal Rectangle Python Hard
86 Partition List Python Medium
88 Merge Sorted Array Java Easy
92 Reverse Linked List II Java Medium
98 Validate Binary Search Tree Java Medium
100 Same Tree Java Easy
101 Symmetric Tree Java Easy
102 Binary Tree Level Order Traversal Java,Python Medium
103 Binary Tree Zigzag Level Order Traversal Python Medium
104 Maximum Depth of Binary Tree Java,Python Easy
105 Construct Binary Tree from Preorder and Inorder Traversal Python Medium
106 Construct Binary Tree from Inorder and Postorder Traversal Python Medium
107 Binary Tree Level Order Traversal II Java Easy
108 Convert Sorted Array to Binary Search Tree Python Easy
109 Convert Sorted List to Binary Search Tree Python Medium
110 Balanced Binary Tree Java Easy
111 Minimum Depth of Binary Tree Java Easy
112 Path Sum Java,Python Easy
113 Path Sum II Java,Python Medium
118 Pascal's Triangle Java Easy
119 Pascal's Triangle II Java Easy
121 Best Time to Buy and Sell Stock Python Easy
125 Valid Palindrome Java Easy
127 Word Ladder Python,Java Medium
129 Sum Root to Leaf Numbers Java Medium
131 Palindrome Partitioning Python Medium
134 Gas Station Python Medium
135 Candy Python Hard
136 Single Number Java Medium
137 Single Number II Java Medium
138 Copy List with Random Pointer Java Hard
139 Word Break Java Medium
141 Linked List Cycle Java Medium
142 Linked List Cycle II Java Medium
144 Binary Tree Preorder Traversal Python Medium
145 Binary Tree Postorder Traversal Python Hard
146 LRU Cache Python Medium
147 Insertion Sort List Python Medium
148 Sort List Python Medium
149 Max Points on a Line Java Hard
150 Evaluate Reverse Polish Notation Python Medium
151 Reverse Words in a String Python Medium
152 Maximum Product Subarray Python Medium
153 Find Minimum in Rotated Sorted Array Python Medium
155 Min Stack Java,Python Easy
160 Intersection of Two Linked Lists Java,Python Easy
162 Find Peak Element Java,Python Medium
165 Compare Version Numbers Java,Python Medium
166 Fraction to Recurring Decimal Python Medium
167 Two Sum II - Input array is sorted Python Easy
168 Excel Sheet Column Title Python Easy
169 Majority Element Java,Python Easy
171 Excel Sheet Column Number Python Easy
172 Factorial Trailing Zeroes Python Easy
173 Binary Search Tree Iterator Python Medium
175 Combine Two Tables SQL Easy
176 Second Highest Salary SQL Easy
177 Nth Highest Salary SQL Medium
178 Rank Scores SQL Medium
179 Largest Number Python Medium
180 Consecutive Numbers SQL Medium
181 Employees Earning More Than Their Managers SQL Easy
182 Duplicate Emails SQL Easy
183 Customers Who Never Order SQL Easy
184 Department Highest Salary SQL Medium
185 Department Top Three Salaries SQL Hard
187 Repeated DNA Sequences Java,Python Medium
188 Best Time to Buy and Sell Stock IV Python Hard
189 Rotate Array Java,Python Easy
190 Reverse Bits Java,Python Easy
191 Number of 1 Bits Java,Python Easy
192 Word Frequency Shell Medium
193 Valid Phone Numbers Shell Easy
194 Transpose File Shell Medium
195 Tenth Line Shell Easy
196 Delete Duplicate Emails SQL Easy
197 Rising Temperature SQL Easy
198 House Robber Java,Python Easy
199 Binary Tree Right Side View Python Medium
200 Number of Islands Python Medium
201 Bitwise AND of Numbers Range Python Medium
202 Happy Number Java Easy
203 Remove Linked List Elements Java,Python Easy
204 Count Primes Python Easy
205 Isomorphic Strings Java,Python Easy
206 Reverse Linked List Java,Python Easy
207 Course Schedule Python Medium
208 Implement Trie (Prefix Tree) Python Medium
209 Minimum Size Subarray Sum Python Medium
210 Course Schedule II Python Medium
211 Add and Search Word - Data structure design Python Medium
212 Word Search II Python Hard
213 House Robber II Python Medium
215 Kth Largest Element in an Array Python Medium
216 Combination Sum III Python Medium
217 Contains Duplicate Java,Python Easy
218 The Skyline Problem Python Hard
219 Contains Duplicate II Java,Python Easy
220 Contains Duplicate III Python Medium
221 Maximal Square Python Medium
222 Count Complete Tree Nodes Python Medium
226 Implement Stack using Queues Python Easy
227 Basic Calculator II Python Medium
228 Summary Ranges Java,Python Medium
229 Majority Element II Java,Python Medium
230 Kth Smallest Element in a BST Python Medium
231 Power of Two Python Easy
232 Implement Queue using Stacks Python Easy
233 Number of Digit One C++,Python Hard
234 Palindrome Linked List Java,Python Easy
235 Lowest Common Ancestor of a Binary Search Tree Java,Python Easy
236 Lowest Common Ancestor of a Binary Tree Python Easy
237 Delete Node in a Linked List C++,Python Easy
238 Product of Array Except Self Python Medium
242 Valid Anagram Java Easy
257 Binary Tree Paths Java Easy
258 Add Digits C++ Easy
260 Single Number III Java Medium
262 Trips and Users SQL Hard
263 Ugly Number Java Easy
264 Ugly Number II Java Medium
268 Missing Number Java Medium
273 Integer to English Words Java Medium
274 H-Index Java Medium
275 H-Index II Java Medium
279 Perfect Squares Java Medium
283 Move Zeroes C++ Easy
284 Peeking Iterator Java Medium
287 Find the Duplicate Number Java,Python Medium
290 Word Pattern Java Easy
292 Nim Game C++ Easy
295 Find Median from Data Stream Java Hard
299 Bulls and Cows Java Easy
300 Longest Increasing Subsequence Java Medium
303 Range Sum Query - Immutable Java Easy
304 Range Sum Query 2D - Immutable Java Medium
317 Shortest Distance from All Buildings Python Hard
328 Odd Even Linked List Java Medium
330 Patching Array Java Hard
338 Counting Bits Java Medium
344 Reverse String Java Easy
367 Valid Perfect Square C++ Easy
371 Sum of Two Integers Java Easy
389 Find the Difference Python Easy
392 Is Subsequence Java,Python Easy
394 Decode String Python Medium
437 Path Sum III Java Easy
438 Find All Anagrams in a String Java Easy
445 Add Two Numbers II Python Medium
448 Find All Numbers Disappeared in an Array Java Easy
461 Hamming Distance Java Easy
485 Max Consecutive Ones Java Easy
496 Next Greater Element I Python Easy
500 Keyboard Row Python Easy
503 Next Greater Element II Java Medium
532 K-diff Pairs in an Array Python Medium
538 Convert BST to Greater Tree Java Easy
543 Diameter of Binary Tree Java,Python Easy
560 Subarray Sum Equals K Java Medium
561 Array Partition I Python Easy
572 Subtree of Another Tree Java Easy
581 Shortest Unsorted Continuous Subarray Java Easy
595 Big Countries SQL Easy
596 Classes More Than 5 Students SQL Easy
601 Human Traffic of Stadium SQL Hard
605 Can Place Flowers Java Easy
617 Merge Two Binary Trees Java Easy
620 Not Boring Movies SQL Easy
626 Exchange Seats SQL Medium
627 Swap Salary SQL Easy
643 Maximum Average Subarray I Python Easy
645 Set Mismatch Python Easy
653 Two Sum IV - Input is a BST Python Easy
657 Judge Route Circle Python Easy
661 Image Smoother Python Easy
665 Non-decreasing Array Python Easy
669 Trim a Binary Search Tree Python Easy
670 Maximum Swap Python Medium
671 Second Minimum Node In a Binary Tree Python Easy
674 Longest Continuous Increasing Subsequence Python Easy
680 Valid Palindrome II Python Easy
682 Baseball Game Python Easy
686 Repeated String Match Python Easy
687 Longest Univalue Path Python Easy
690 Employee Importance Python Easy
693 Binary Number with Alternating Bits Python Easy
695 Max Area of Island Python Easy
696 Count Binary Substrings Python Easy
697 Degree of an Array Python Easy
700 Search in a Binary Search Tree Python Easy
704 Binary Search Python Easy
705 Design HashSet Python Easy
706 Design HashMap Python Easy
707 Design Linked List Python Easy
709 To Lower Case Python Easy
717 1-bit and 2-bit Characters Python Easy
720 Longest Word in Dictionary Python Easy
724 Find Pivot Index Python Easy
728 Self Dividing Numbers Python Easy
733 Flood Fill Python Easy
744 Find Smallest Letter Greater Than Target Python Easy
746 Min Cost Climbing Stairs Python Easy
747 Largest Number At Least Twice of Others Python Easy
762 Prime Number of Set Bits in Binary Representation Python Easy
766 Toeplitz Matrix Python Easy
771 Jewels and Stones Python Easy
784 Letter Case Permutation Python Easy
788 Rotated Digits Python Easy
796 Rotate String Python Easy
804 Unique Morse Code Words Python Easy
806 Number of Lines To Write String Python Easy
811 Subdomain Visit Count Python Easy
812 Largest Triangle Area Python Easy
819 Most Common Word Python Easy
821 Shortest Distance to a Character Python Easy
824 Goat Latin Python Easy
830 Positions of Large Groups Python Easy
832 Flipping an Image Java Easy
836 Rectangle Overlap Python Easy
840 Magic Squares In Grid Python Easy
844 Backspace String Compare Python Easy
849 Maximize Distance to Closest Person Python Easy
852 Peak Index in a Mountain Array Python Easy
859 Buddy Strings Python Easy
860 Lemonade Change Python Easy
867 Binary Gap Python Easy
868 Transpose Matrix Python Easy
872 Leaf-Similar Trees Java Easy
874 Walking Robot Simulation Java Easy
876 Middle of the Linked List Python Easy
880 Decoded String at Index Python Medium
881 Boats to Save People Python Medium
883 Projection Area of 3D Shapes Java Easy
884 Uncommon Words from Two Sentences Python Easy
885 Spiral Matrix III Python Medium
888 Fair Candy Swap Python Easy
892 Surface Area of 3D Shapes Python Easy
893 Groups of Special-Equivalent Strings Python Easy
894 All Possible Full Binary Trees Python Medium
933 Number of Recent Calls Python Easy
958 Check Completeness of a Binary Tree Python Medium
1029 Check If It Is a Straight Line Python Easy
1035 Uncrossed Lines Python Medium
1044 Longest Duplicate Substring Python Hard
1049 Last Stone Weight II Python Medium
1071 Greatest Common Divisor of Strings Python Easy
1143 Longest Common Subsequence Python Medium
1232 Check If It Is a Straight Line Python Easy
1277 Count Square Submatrices with All Ones Python Medium
1344 Angle Between Hands of a Clock Python Medium

Features

  • Contains a lot of interview questions and still constantly adding!
  • Many languages are used for problems -- you can choose what you want!

Quick Start

Clone it. Have a look at the solutions or some particular question and get inpired!

Contribution Guide

You can choose any problem in LeetCode and bring your solution here. However, notice the folder structure of current repo

--algorithms         # contains solutions for algorithmic problems in LeetCode
  --3sum             # named after the question itself
    --Solution.java  # actual code for the solution. the problem description and maybe even explanation
                     #   for the solution are in the form of comments
--shell              # solutions for shell related problems
--databases          # solutions for database related problems
  1. Fork the repository.
  2. Solve the problem in LeetCode.
  3. Create the solution file in the correct directory and add the link to README table.
  4. Create pull request.
  5. After review and discussions, the patch will be merged!

Question and Help

You are welcome to use Issue Trackers in the repository to bring up any questions!

License

MIT license. You are free to contribute or hack!

leetcode-solutions's People

Contributors

franklingu avatar thyageshm avatar roastedbill avatar atri2107 avatar praneshasp avatar souravkr avatar

Watchers

James Cloos 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.