Skip to content

guker/Lintcode-2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

LintCode

Up to date (2015-08-15), there are 251 problems on LintCode Online Judge. The number of problems is increasing recently. Here is the classification of all the solved problems. For extra problems and solutions, you can see my LeetCode repo. I'll keep updating for full summary and better solutions. Stay tuned for updates.


Algorithms


##Bit Manipulation

# Title Solution Time Space Difficulty Tag Note
1 A + B Problem [Cpp](./Cpp/A + B Problem.cpp) O(1) O(1) Hard
82 Single Number [Cpp](./Cpp/Single Number.cpp) O(n) O(1) Easy
83 Single Number II [Cpp](./Cpp/Single Number II.cpp) O(n) O(1) Medium
84 Single Number III [Cpp](./Cpp/Single Number III.cpp) O(n) O(1) Medium
142 O(1) Check Power of 2 [Cpp](./Cpp/O(1)Check Power of 2.cpp) O(1) O(1) Easy
179 Update Bits [Cpp](./Cpp/[Update Bits.cpp) O(1) O(1) Medium
181 Convert Integer A to Integer B [Cpp](./Cpp/Convert Integer A to Integer B.cpp) O(1) O(1) Easy

##Array

# Title Solution Time Space Difficulty Tag Note
6 Merge Sorted Array [Cpp](./Cpp/Merge Sorted Array.cpp) O(m + n) O(1) Easy LeetCode Two Pointers
8 Rotate String [Cpp](./Cpp/Rotate String.cpp) O(n) O(1) Easy LeetCode
9 Fizz Buzz [Cpp](./Cpp/Fizz Buzz.cpp) O(n) O(1) Easy
30 Insert Interval [Cpp](./Cpp/Insert Interval.cpp) O(n) O(1) Easy LeetCode
31 Partition Array [Cpp](./Cpp/Partition Array.cpp) O(n) O(1) Medium Two Pointers
32 Minimum Window Substring [Cpp](./Cpp/Minimum Window Substring.cpp) O(n) O(1) Medium Two Pointers
38 Search a 2D Matrix II [Cpp](./Cpp/Search a 2D Matrix II.cpp) O(m + n) O(1) Medium
39 Recover Rotated Sorted Array [Cpp](./Cpp/Recover Rotated Sorted Array.cpp) O(n) O(1) Easy
46 Majority Number [Cpp](./Cpp/Majority Number.cpp) O(n) O(1) Easy LeetCode
47 Majority Number II [Cpp](./Cpp/Majority Number II.cpp) O(n) O(1) Medium
48 Majority Number III [Cpp](./Cpp/Majority Number III.cpp) O(n) O(k) Medium Heap
49 Sort Letters by Case [Cpp](./Cpp/Sort Letters by Case.cpp) O(n) O(1) Medium Two Pointers
50 Product of Array Exclude Itself [Cpp](./Cpp/Product of Array Exclude Itself.cpp) O(n) O(n) Easy
51 Previous Permutation [Cpp](./Cpp/Previous Permutation.cpp) O(n) O(1) Medium
52 Next Permutation [Cpp](./Cpp/Next Permutation.cpp) O(n) O(1) Medium LeetCode
57 3 Sum [Cpp](./Cpp/3 Sum.cpp) O(n^2) O(1) Medium LeetCode Two Pointers, Sort
59 3 Sum Closest [Cpp](./Cpp/3 Sum Closest.cpp) O(n^2) O(1) Medium LeetCode Two Pointers, Sort
64 Merge Sorted Array II [Cpp](./Cpp/Merge Sorted Array II.cpp) O(m + n) O(1) Easy LeetCode Two Pointers
100 Remove Duplicates from Sorted Array [Cpp](./Cpp/Remove Duplicates from Sorted Array.cpp) O(n) O(1) Easy LeetCode Two Pointers
101 Remove Duplicates from Sorted Array II [Cpp](./Cpp/Remove Duplicates from Sorted Array II.cpp) O(n) O(1) Easy LeetCode Two Pointers
144 Interleaving Positive and Negative Numbers [Cpp](./Cpp/Interleaving Positive and Negative Numbers.cpp) O(n) O(1) Medium Two Pointers
161 Rotate Image [Cpp](./Cpp/Rotate Image.cpp) O(n) O(1) Medium LeetCode
162 Set Matrix Zeroes [Cpp](./Cpp/Set Matrix Zeroes.cpp) O(n) O(1) Medium LeetCode
172 Remove Element [Cpp](./Cpp/Remove Element.cpp) O(n) O(1) Easy LeetCode Two Pointers
185 Matrix Zigzag Traversal [Cpp](./Cpp/Matrix Zigzag Traversal.cpp) O(m * n) O(1) Easy
189 First Missing Positive [Cpp](./Cpp/First Missing Positive.cpp) O(n) O(1) Easy LeetCode, EPI Hash
363 Trapping Rain Water [Cpp](./Cpp/Trapping Rain Water.cpp) O(n) O(1) Medium LeetCode Two Pointers, Tricky
383 Container With Most Water [Cpp](./Cpp/Container With Most Water.cpp) O(n) O(1) Medium LeetCode, EPI Two Pointers
388 Permutation Sequence [Cpp](./Cpp/Permutation Sequence.cpp) O(n^2) O(n) Medium LeetCode
389 Valid Sudoku [Cpp](./Cpp/Valid Sudoku.cpp) O(9^2) O(9) Easy LeetCode

##String

# Title Solution Time Space Difficulty Tag Note
13 strStr Cpp O(n) O(k) Easy LeetCode KMP Algorithm
53 Reverse Words in a String [Cpp](./Cpp/Reverse Words in a String.cpp) O(n) O(1) Easy LeetCode
54 Convert String to Integer [Cpp](./Cpp/Convert String to Integer.cpp) O(n) O(1) Hard LeetCode
55 Compare Strings [Cpp](./Cpp/Compare Strings.cpp) O(n) O(c) Easy
78 Longest Common Prefix [Cpp](./Cpp/Longest Common Prefix.cpp) O(n) O(1) Medium
157 Unique Characters [Cpp](./Cpp/Unique Characters.cpp) O(n) O(1) Easy CTCI
158 Two Strings Are Anagrams [Cpp](./Cpp/Two Strings Are Anagrams.cpp) O(n) O(1) Easy
171 Anagrams Cpp O(n * klogk) O(m) Easy LeetCode, EPI

##Linked List

# Title Solution Time Space Difficulty Tag Note
16 Merge Two Sorted Lists [Cpp](./Cpp/Merge Two Sorted Lists.cpp) O(n) O(1) Easy LeetCode, EPI
35 Reverse Linked List [Cpp](./Cpp/Reverse Linked List.cpp) O(n) O(1) Easy LeetCode, EPI
36 Reverse Linked List II [Cpp](./Cpp/Reverse Linked List II.cpp) O(n) O(1) Medium LeetCode, EPI
96 Partition List [Cpp](./Cpp/Partition List.cpp) O(n) O(1) Easy LeetCode
98 Sort List [Cpp](./Cpp/Sort List.cpp) O(nlogn) O(logn) Medium LeetCode, EPI
99 Reorder List [Cpp](./Cpp/Reorder List.cpp) O(n) O(1) Medium LeetCode
102 Linked List Cycle [Cpp](./Cpp/Linked List Cycle.cpp) O(n) O(1) Medium LeetCode
103 Linked List Cycle II [Cpp](./Cpp/Linked List Cycle II.cpp) O(n) O(1) Hard LeetCode
105 Copy List with Random Pointer [Cpp](./Cpp/Copy List with Random Pointer.cpp) O(n) O(1) Medium LeetCode
106 Convert Sorted List to Binary Search Tree [Cpp](./Cpp/Convert Sorted List to Binary Search Tree.cpp) O(n) O(logn) Medium LeetCode, EPI
112 Remove Duplicates from Sorted List [Cpp](./Cpp/Remove Duplicates from Sorted List.cpp) O(n) O(1) Easy LeetCode, EPI
113 Remove Duplicates from Sorted List II [Cpp](./Cpp/Remove Duplicates from Sorted List II.cpp) O(n) O(1) Medium LeetCode, EPI
166 Nth to Last Node in List [Cpp](./Cpp/Nth to Last Node in List.cpp) O(n) O(1) Easy LeetCode
167 Two Lists Sum [Cpp](./Cpp/Two Lists Sum.cpp) O(n) O(1) Easy LeetCode
170 Rotate List [Cpp](./Cpp/Rotate List.cpp) O(n) O(1) Medium LeetCode
173 Insertion Sort List [Cpp](./Cpp/Insertion Sort List.cpp) O(n^2) O(1) Easy LeetCode
174 Remove Nth Node From End of List [Cpp](./Cpp/Remove Nth Node From End of List.cpp) O(n) O(1) Easy LeetCode

##Tree

# Title Solution Time Space Difficulty Tag Note
85 Insert Node in a Binary Search Tree [Cpp](./Cpp/Insert Node in a Binary Search Tree.cpp) O(h) O(1) Easy
88 Lowest Common Ancestor [Cpp](./Cpp/Lowest Common Ancestor.cpp) O(n) O(h) Medium EPI
127 Max Tree [Cpp](./Cpp/Max Tree.cpp) O(n) O(n) Hard

##Stack

# Title Solution Time Space Difficulty Tag Note
12 Min Stack [Cpp](./Cpp/Min Stack.cpp) O(n) O(1) Medium LeetCode, EPI
40 Implement Queue by Two Stacks [Cpp](./Cpp/Implement Queue by Two Stacks.cpp) O(1), amortized O(n) Medium EPI
66 Binary Tree Preorder Traversal [Cpp](./Cpp/Binary Tree Preorder Traversal.cpp) O(n) O(1) Easy LeetCode, EPI Morris Traversal
67 Binary Tree Inorder Traversal [Cpp](./Cpp/Binary Tree Inorder Traversal.cpp) O(n) O(1) Easy LeetCode, EPI Morris Traversal
68 Binary Tree Postorder Traversal [Cpp](./Cpp/Binary Tree Postorder Traversal.cpp) O(n) O(1) Easy LeetCode, EPI Morris Traversal
122 Largest Rectangle in Histogram [Cpp](./Cpp/Largest Rectangle in Histogram.cpp) O(n) O(n) Hard LeetCode, EPI
367 Expression Tree Build [Cpp](./Cpp/Expression Tree Build.cpp) O(n) O(n) Hard
368 Expression evaluation [Cpp](./Cpp/Expression evaluation.cpp) O(n) O(n) Hard
369 Convert Expression to Polish Notation [Cpp](./Cpp/Convert Expression to Polish Notation.cpp) O(n) O(n) Hard
370 Convert Expression to Reverse Polish Notation [Cpp](./Cpp/Convert Expression to Reverse Polish Notation.cpp) O(n) O(n) Hard

##Queue

# Title Solution Time Space Difficulty Tag Note
362 Sliding Window Maximum [Cpp](./Cpp/Sliding Window Maximum.cpp) O(n) O(k) Hard EPI Deque, Tricky

##Heap

# Title Solution Time Space Difficulty Tag Note
4 Ugly Number [Cpp](./Cpp/Ugly Number.cpp) O(k) O(1) Medium CTCI
81 Median in Data Stream [Cpp](./Cpp/Median in Data Stream.cpp) O(nlogn) O(n) Hard EPI BST, Heap
104 Merge k Sorted Lists [Cpp](./Cpp/Merge k Sorted Lists.cpp) O(n * logk) O(k) Medium LeetCode
130 Heapify Cpp O(n) O(1) Medium
364 Trapping Rain Water II [Cpp](./Cpp/Trapping Rain Water II.cpp) O(n^2 * logn) O(n^2) Hard BFS, Heap, Tricky

##Hash Tables

# Title Solution Time Space Difficulty Tag Note
56 2 Sum [Cpp](./Cpp/2 Sum.cpp) O(n) O(n) Medium LeetCode
58 4 Sum [Cpp](./Cpp/4 Sum.cpp) O(n^2 * p) O(n^2 * p) Medium LeetCode Hash
124 Longest Consecutive Sequence [Cpp](./Cpp/Longest Consecutive Sequence.cpp) O(n) O(n) Medium LeetCode, EPI
128 Hash Function [Cpp](./Cpp/Hash Function.cpp) O(n) O(1) Easy
129 Rehashing Cpp O(n) O(n) Medium
138 Subarray Sum [Cpp](./Cpp/Subarray Sum.cpp) O(n) O(n) Easy
384 Longest Substring Without Repeating Characters [Cpp](./Cpp/Longest Substring Without Repeating Characters.cpp) O(n) O(1) Medium LeetCode, EPI
386 Longest Substring with At Most K Distinct Characters [Cpp](./Cpp/Longest Substring with At Most K Distinct Characters.cpp) O(n) O(n) Medium

##Data Structure

# Title Solution Time Space Difficulty Tag Note
134 LRU Cache [Cpp](./Cpp/LRU Cache.cpp) O(1) O(c) Hard LeetCode, EPI List, Hash

##Math

# Title Solution Time Space Difficulty Tag Note
2 Trailing Zeros [Cpp](./Cpp/Trailing Zeros.cpp) O(logn) O(1) Easy LeetCode
3 Digit Counts [Cpp](./Cpp/Digit Counts.cpp) O(logn) O(1) Medium CTCI
114 Unique Paths [Cpp](./Cpp/Unique Paths.cpp) O(min(m, n)) O(1) Easy LeetCode, CTCI DP, Math
163 Unique Binary Search Trees [Cpp](./Cpp/Unique Binary Search Trees.cpp) O(n) O(1) Medium CTCI DP, Math, Catalan Number
180 Binary Represention [Cpp](./Cpp/Binary Represention.cpp) O(1) O(1) Hard CTCI

##Sort

# Title Solution Time Space Difficulty Tag Note
5 Kth Largest Element [Cpp](./Cpp/Kth Largest Element.cpp) O(n) O(1) Medium EPI Two Pointers, Quick Sort
80 Median Cpp O(n) O(1) Easy EPI
139 Subarray Sum Closest [Cpp](./Cpp/Subarray Sum Closest.cpp) O(nlogn) O(n) Medium Sort
143 Sort Colors II [Cpp](./Cpp/Sort Colors II.cpp) O(n) O(1) Medium
148 Sort Colors [Cpp](./Cpp/Sort Colors.cpp) O(n) O(1) Medium LeetCode
184 Largest Number [Cpp](./Cpp/Largest Number.cpp) O(nlogn) O(1) Medium LeetCode
387 The Smallest Difference [Cpp](./Cpp/The Smallest Difference.cpp) O(nlogn) O(1) Medium Two Pointers

##Divide and Conquer

# Title Solution Time Space Difficulty Tag Note
17 Subsets Cpp O(n * 2^n) O(1) Medium LeetCode
18 Subsets II Cpp O(n * 2^n) O(1) Medium LeetCode
72 Construct Binary Tree from Inorder and Postorder Traversal Cpp O(n) O(h) Medium LeetCode, EPI
73 Construct Binary Tree from Preorder and Inorder Traversal Cpp O(n) O(h) Medium LeetCode, EPI
93 Balanced Binary Tree Cpp O(n) O(h) Easy LeetCode
94 Binary Tree Maximum Path Sum Cpp O(n) O(h) Medium LeetCode
95 Validate Binary Search Tree Cpp O(n) O(h) Medium LeetCode
97 Maximum Depth of Binary Tree Cpp O(n) O(h) Easy LeetCode
131 Building Outline Cpp O(nlogn) O(n) Hard EPI
140 Fast Power Cpp O(logn) O(logn) Medium
155 Minimum Depth of Binary Tree Cpp O(n) O(h) Easy LeetCode
164 Unique Binary Search Trees II Cpp O(n * 4^n / n^(3/2)) O(n) Medium LeetCode
201 Segment Tree Build Cpp O(n) O(h) Medium Segment Tree, BST
202 Segment Tree Query Cpp O(h) O(h) Medium Segment Tree, BST
203 Segment Tree Modify Cpp O(h) O(h) Medium Segment Tree, BST
205 Interval Minimum Number Cpp build tree: O(n), query: (h) O(h) Hard Segment Tree, BST
206 Interval Sum Cpp build tree: O(n), query: O(h) O(h) Hard Segment Tree, BST
207 Interval Sum II Cpp build tree: O(n), query: O(h), modify: O(h) O(h) Hard Segment Tree, BST
247 Segment Tree Query II Cpp O(h) O(h) Hard Segment Tree, BST
248 Count of Smaller Number Cpp build tree: O(n), query: O(logn) O(h) Medium Segment Tree, BST

##Binary Search

# Title Solution Time Space Difficulty Tag Note
14 Binary Search Cpp O(logn) O(1) Easy
28 Search a 2D Matrix Cpp O(logm + logn) O(1) Easy LeetCode
60 Search Insert Position Cpp O(logn) O(1) Easy LeetCode
61 Search for a Range Cpp O(logn) O(1) Medium LeetCode
62 Search in Rotated Sorted Array Cpp O(logn) O(1) Hard LeetCode
63 Search in Rotated Sorted Array II Cpp O(logn) O(1) Medium LeetCode
65 Median of two Sorted Arrays Cpp O(log(min(m, n))) O(1) Hard LeetCode, EPI Tricky
74 First Bad Version Cpp O(logn) O(1) Medium
75 Find Peak Element Cpp O(logn) O(1) Medium LeetCode
76 Longest Increasing Subsequence Cpp O(nlogn) O(n) Medium CTCI
141 Sqrt(x) Cpp O(logn) O(1) Easy LeetCode
159 Find Minimum in Rotated Sorted Array Cpp O(logn) O(1) Medium LeetCode
160 Find Minimum in Rotated Sorted Array II Cpp O(logn) O(1) Medium LeetCode
183 Wood Cut Cpp O(nlogL) O(1) Medium
249 Count of Smaller Number before itself Cpp O(nlogn) O(h) Hard
390 Find Peak Element II Cpp Java Python O(m + n) O(1) Hard

##Depth First Search

# Title Solution Time Space Difficulty Tag Note
15 Permutations Cpp O(n * n!) O(n) Medium LeetCode, EPI
16 Permutations II Cpp O(n * n!) O(n) Medium LeetCode, EPI
33 N-Queens Cpp O(n * n!) O(n) Medium LeetCode, EPI
34 N-Queens II Cpp O(n * n!) O(n) Medium LeetCode, EPI
90 K Sum II Cpp O(k * C(n, k)) O(k) Medium
123 Word Search Cpp O(m * n * l) O(l) Medium LeetCode
132 Word Search II Cpp O(m * n * l) O(l) Hard Trie, DFS
135 Combination Sum Cpp O(k * n^k) O(k) Medium LeetCode DFS
136 Palindrome Partitioning Cpp O(2^n) O(n) Easy LeetCode, EPI
152 Combinations Cpp O(k * n^k) O(k) Medium LeetCode, EPI
153 Combination Sum II Cpp O(k * C(n, k)) O(k) Medium LeetCode DFS

##Breadth First Search

# Title Solution Time Space Difficulty Tag Note
69 Binary Tree Level Order Traversal Cpp O(n) O(n) Medium LeetCode BFS
70 Binary Tree Level Order Traversal II Cpp O(n) O(n) Medium LeetCode BFS
71 Binary Tree Zigzag Level Order Traversal Cpp O(n) O(n) Medium LeetCode BFS
120 Word Ladder Cpp O(n * d) O(d) Medium LeetCode BFS
121 Word Ladder II Cpp O(n * d) O(d) Hard LeetCode BFS, Back Trace
127 Topological Sorting Cpp O(|V|+|E|) O(|E|) Medium DFS, BFS
137 Clone Graph Cpp O(|V|+|E|) O(|V|) Medium BFS
176 Route Between Two Nodes in Graph Cpp O(n) O(n) Medium DFS, BFS

##Binary Search Trees

# Title Solution Time Space Difficulty Tag Note
7 Binary Tree Serialization Cpp O(n) O(h) Medium LeetCode
11 Search Range in Binary Search Tree Cpp O(n) O(h) Medium EPI
84 Remove Node in Binary Search Tree Cpp O(h) O(h) Hard
85 Implement Iterator of Binary Search Tree Cpp O(1) O(h) Hard LeetCode
360 Sliding Window Median Cpp O(nlogw) O(w) Hard BST, Tricky
391 Number of Airplanes in the Sky Cpp O(nlogn) O(1) Easy BST, Heap

##Dynamic Programming

# Title Solution Time Space Difficulty Tag Note
29 Interleaving String Cpp O(m * b) O(min(m, n)) Medium EPI
43 Maximum Subarray III Cpp O(k * n^2) O(k * n) Hard
77 Longest Common Sequence Cpp O(m * n) O(min(m, n)) Medium
79 Longest Common Substring Cpp O(m * n) O(min(m, n)) Medium
89 K Sum Cpp O(k * n * t) O(n * t) Hard
91 Minimum Adjustment Cost Cpp O(k * n * t) O(k) Medium
92 Backpack Cpp O(m * n) O(m) Easy
107 Word Segmentation Cpp O(n^2) O(n) Medium LeetCode, EPI
108 Palindrome Partitioning II Cpp O(n^2) O(n) Medium LeetCode, EPI
109 Triangle Cpp O(n) O(n) Easy LeetCode, EPI
110 Minimum Path Sum Cpp O(m * n) O(min(m, n)) Easy LeetCode, EPI
111 Climbing Stairs Cpp O(n) O(1) Easy LeetCode
115 Unique Paths II Cpp O(m * n) O(min(m, n)) Easy LeetCode, CTCI DP, Math
118 Distinct Subsequences Cpp O(m * n) O(m) Medium LeetCode DP
119 Edit Distance Cpp O(m * n) O(min(m, n)) Medium LeetCode, CTCI DP
125 Backpack II Cpp O(m * n) O(m) Medium
149 Best Time to Buy and Sell Stock Cpp O(n) O(1) Medium LeetCode, EPI
150 Best Time to Buy and Sell Stock II Cpp O(n) O(1) Medium LeetCode, EPI
151 Best Time to Buy and Sell Stock III Cpp O(n) O(1) Medium LeetCode, EPI
152 Regular Expression Matching Cpp O(m * n) O(m) Hard LeetCode DP, Recursion
191 Maximum Product Subarray Cpp O(n) O(1) Medium LeetCode

##Greedy

# Title Solution Time Space Difficulty Tag Note
41 Maximum Subarray Cpp O(n) O(1) Easy LeetCode
42 Maximum Subarray II Cpp O(n) O(n) Medium
44 Minimum Subarray Cpp O(n) O(1) Easy
45 Maximum Subarray Difference Cpp O(n) O(n) Medium
116 Jump Game Cpp O(n) O(1) Medium LeetCode
117 Jump Game II Cpp O(n) O(1) Medium LeetCode
182 Delete Digits Cpp O(n) O(n) Medium
187 Gas Station Cpp O(n) O(1) Easy LeetCode
192 Wildcard Matching Cpp O(m + n) O(1) Hard LeetCode Greedy, DP, Recursion

##Design Pattern

# Title Solution Time Space Difficulty Tag Note
204 Singleton Cpp O(1) O(1) Easy
208 Assignment Operator Overloading(Cpp Only) Cpp O(1) O(1) Medium OO Design

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 45.3%
  • Java 45.3%
  • Python 9.4%