/leetcode-c-programming

Pure C solution for LeetCode

Primary LanguageC

Pure C solution for LeetCode

This project aims at solving LeetCode algorithm problems with pure C Language using as little library functions as I can, which means except memory management functions and few string functions I will implement everything I need such as trees, stacks, queues and hash tables.

Parts of the problems don't provide C interface for solution, so I accomplished them with C++ Language.

Compile C files using command:

gcc -std=c99 -Wall src/foo.c -o foo

Compile C++ files using command:

g++ -std=c++11 -Wall src/bar.cpp -o bar

OR

You can build all the files using make (Use MinGW GCC and GNU Make on Windows).

Problem Solution
237 Delete Node in a Linked List C
236 Lowest Common Ancestor of a Binary Tree
235 Lowest Common Ancestor of a Binary Search Tree C
234 Palindrome Linked List C
233 Number of Digit One
232 Implement Queue using Stacks C
231 Power of Two C
230 Kth Smallest Element in a BST C
229 Majority Element II
228 Summary Ranges C
227 Basic Calculator II
226 Invert Binary Tree C
225 Implement Stack using Queues C
224 Basic Calculator C
223 Rectangle Area C
222 Count Complete Tree Nodes C
221 Maximal Square
220 Contains Duplicate III
219 Contains Duplicate II C
218 The Skyline Problem
217 Contains Duplicate C
216 Combination Sum III
215 Kth Largest Element in an Array C
214 Shortest Palindrome
213 House Robber II
212 Word Search II C
211 Add and Search Word - Data structure design C
210 Course Schedule II
209 Minimum Size Subarray Sum
208 Implement Trie (Prefix Tree) C
207 Course Schedule
206 Reverse Linked List C
205 Isomorphic Strings C
204 Count Primes C
203 Remove Linked List Elements C
202 Happy Number C
201 Bitwise AND of Numbers Range C
200 Number of Islands C
199 Binary Tree Right Side View C
198 House Robber C
191 Number of 1 Bits C
190 Reverse Bits C
189 Rotate Array C
188 Best Time to Buy and Sell Stock IV
187 Repeated DNA Sequences
186 Reverse Words in a String II
179 Largest Number
174 Dungeon Game
173 Binary Search Tree Iterator
172 Factorial Trailing Zeroes C
171 Excel Sheet Column Number C
170 Two Sum III - Data structure design
169 Majority Element C
168 Excel Sheet Column Title C
167 Two Sum II - Input array is sorted
166 Fraction to Recurring Decimal
165 Compare Version Numbers C
164 Maximum Gap C
163 Missing Ranges
162 Find Peak Element
161 One Edit Distance
160 Intersection of Two Linked Lists C
159 Longest Substring with At Most Two Distinct Characters
158 Read N Characters Given Read4 II - Call multiple times
157 Read N Characters Given Read4
156 Binary Tree Upside Down
155 Min Stack C
154 Find Minimum in Rotated Sorted Array II
153 Find Minimum in Rotated Sorted Array
152 Maximum Product Subarray C
151 Reverse Words in a String C
150 Evaluate Reverse Polish Notation C
149 Max Points on a Line
148 Sort List
147 Insertion Sort List
146 LRU Cache
145 Binary Tree Postorder Traversal C
144 Binary Tree Preorder Traversal C++
143 Reorder List
142 Linked List Cycle II
141 Linked List Cycle C
140 Word Break II
139 Word Break C++
138 Copy List with Random Pointer
137 Single Number II
136 Single Number C
135 Candy
134 Gas Station
133 Clone Graph
132 Palindrome Partitioning II
131 Palindrome Partitioning
130 Surrounded Regions
129 Sum Root to Leaf Numbers
128 Longest Consecutive Sequence C
127 Word Ladder
126 Word Ladder II
125 Valid Palindrome C
124 Binary Tree Maximum Path Sum
123 Best Time to Buy and Sell Stock III
122 Best Time to Buy and Sell Stock II C
121 Best Time to Buy and Sell Stock C
120 Triangle C
119 Pascal's Triangle II C
118 Pascal's Triangle C
117 Populating Next Right Pointers in Each Node II
116 Populating Next Right Pointers in Each Node
115 Distinct Subsequences
114 Flatten Binary Tree to Linked List
113 Path Sum II
112 Path Sum C
111 Minimum Depth of Binary Tree C
110 Balanced Binary Tree C
109 Convert Sorted List to Binary Search Tree
108 Convert Sorted Array to Binary Search Tree C
107 Binary Tree Level Order Traversal II C++
106 Construct Binary Tree from Inorder and Postorder Traversal C
105 Construct Binary Tree from Preorder and Inorder Traversal C
104 Maximum Depth of Binary Tree C
103 Binary Tree Zigzag Level Order Traversal C++
102 Binary Tree Level Order Traversal C
101 Symmetric Tree C
100 Same Tree C
99 Recover Binary Search Tree
98 Validate Binary Search Tree C
97 Interleaving String
96 Unique Binary Search Trees C
95 Unique Binary Search Trees II C++
94 Binary Tree Inorder Traversal C
93 Restore IP Addresses
92 Reverse Linked List II C
91 Decode Ways C
90 Subsets II
89 Gray Code
88 Merge Sorted Array C
87 Scramble String
86 Partition List
85 Maximal Rectangle
84 Largest Rectangle in Histogram
83 Remove Duplicates from Sorted List C
82 Remove Duplicates from Sorted List II
81 Search in Rotated Sorted Array II C
80 Remove Duplicates from Sorted Array II
79 Word Search
78 Subsets
77 Combinations
76 Minimum Window Substring
75 Sort Colors
74 Search a 2D Matrix
73 Set Matrix Zeroes C
72 Edit Distance C
71 Simplify Path
70 Climbing Stairs C
69 Sqrt(x)
68 Text Justification
67 Add Binary C
66 Plus One C
65 Valid Number C
64 Minimum Path Sum C
63 Unique Paths II C
62 Unique Paths C
61 Rotate List C
60 Permutation Sequence
59 Spiral Matrix II
58 Length of Last Word C
57 Insert Interval
56 Merge Intervals
55 Jump Game
54 Spiral Matrix
53 Maximum Subarray C
52 N-Queens II C
51 N-Queens C++
50 Pow(x, n) C
49 Anagrams
48 Rotate Image C
47 Permutations II
46 Permutations C
45 Jump Game II
44 Wildcard Matching
43 Multiply Strings
42 Trapping Rain Water
41 First Missing Positive
40 Combination Sum II
39 Combination Sum
38 Count and Say C
37 Sudoku Solver
36 Valid Sudoku C
35 Search Insert Position C
34 Search for a Range
33 Search in Rotated Sorted Array C
32 Longest Valid Parentheses
31 Next Permutation
30 Substring with Concatenation of All Words
29 Divide Two Integers
28 Implement strStr() C
27 Remove Element C
26 Remove Duplicates from Sorted Array C
25 Reverse Nodes in k-Group
24 Swap Nodes in Pairs
23 Merge k Sorted Lists
22 Generate Parentheses
21 Merge Two Sorted Lists C
20 Valid Parentheses C
19 Remove Nth Node From End of List C
18 4Sum
17 Letter Combinations of a Phone Number
16 3Sum Closest
15 3Sum
14 Longest Common Prefix C
13 Roman to Integer C
12 Integer to Roman C
11 Container With Most Water
10 Regular Expression Matching
9 Palindrome Number C
8 String to Integer (atoi) C
7 Reverse Integer C
6 ZigZag Conversion C
5 Longest Palindromic Substring
4 Median of Two Sorted Arrays
3 Longest Substring Without Repeating Characters
2 Add Two Numbers C
1 Two Sum C