Skip to content

davidlunadeleon/leetcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

leetcode

These are my solutions to some leetcode problems.

About the contents of this repo

This repository contains solutions to some leetcode problems.

How to use the test cases

The solutions can be directly tested in Leetcode without aditional steps. To test with the included main program, some other steps will be required.

Click me!

For the time being, this process will be a little bit messy until I finish making all libraries and makefiles necessary to compile each program individually.

1. Compile the libraries included in /leetcode/cpp/lib/ with the make command

$ cd ./leetcode/cpp/lib/
$ make

The console terminal should confirm that there are no errors in the compiling process.

Using VSCode

  1. A .vscode directory is located at the root of the project, it includes files to specify the compiling and debugging options to use.
  • To compile simply press Ctrl + Shift + B.
  • To debug press F5.

Compiling yourself

  1. Compile the code of the problem you want to test.

If you are using your own code, be sure to include it after the comment that says //Leetcode solution starts. Don't forget to include the .a file located in /leetcode/cpp/bin/ if a custom library is used.

$ cd ./leetcode/cpp/938-RangeSumOfBST/
$ g++ 938-RangeSumOfBST.cpp ../bin/treeUtils.a -o 938-RangeSumOfBST.bin
  • Use of -Wall -Wextra and -pedantic-erros flags is recommended

3. Use the test cases and print the result either to the terminal or to a file

$ cat testCases | ./938-RangeSumOfBST.bin

Or

$ cat testCases | ./938-RangeSumOfBST.bin > results

Contributing

Contributions of new test cases or code to improve testing of each problem or upgrade functionality of libraries are always welcome. Better solutions to already solved problems are welcome too.

List of problems

Problem # Problem and source Difficulty Language
1 Two Sum Easy C++
2 Add Two Numbers Medium C++ / C
3 Longest Substring Without Repeating Characters Medium C++
5 Longest Palindromic Substring Medium C++
6 ZigZag Conversion Medium C++
7 Reverse Integer Easy C++
9 Palindrome Number Easy C++
11 Container With Most Water Medium C++
13 Roman to Integer Easy C++
14 Longest Common Prefix Easy C++
15 3 Sum Medium C++
17 Letter Combinations of a Phone Number Medium C++
18 4 Sum Medium C++
19 Remove Nth Node From End of List Medium C++
20 Valid Parentheses Easy C++
21 Merge Two Sorted Lists Easy C++
26 Remove Duplicates from Sorted Array Easy C++
27 Remove Element Easy C++
34 Find First and Last Position of Element in Sorted Array Medium C++
35 Search Insert Position Easy C++
41 First Missing Positive Hard C++
57 Insert Interval Hard C++
58 Length of Last Word Easy C++ / C
74 Search a 2D Matrix Medium C++
82 Remove Duplicates from Sorted List II Medium C++
94 Binary Tree Inorder Traversal Medium C++
98 Validate Binary Search Tree Medium C++
119 Pascal's Triangle II Easy C++
121 Best Time to Buy and Sell Stock Easy C++ / C
125 Valid Palindrome Easy C++
134 Gas Station Medium C++ / C
139 Word Break Medium C++
143 Reorder List Medium C++
145 Binary Tree Postorder Traversal Hard C++
152 Maximum Produc Subarray Medium C++
165 Compare Version Number Medium C++
171 Excel Sheet Column Number Easy C++
179 Largest Number Medium C++
198 House Robber Easy C++
206 Reverse Linked List Easy C++
208 Implement Trie (Prefix Tree) Medium C++
215 Kth Largest Element in an Array Medium C++
216 Combination Sum III Medium C++
220 Contains Duplicate III Medium C++
229 Majority Element II Medium C++ / C
230 Kth Smallest Element in a BST Medium C++
274 H-Index Medium C++
290 Word Pattern Easy C++
299 Bulls and Cows Easy C++ / C
312 Burst Balloons Hard C++
342 Power of Four Easy C++
389 Find the Difference Easy C++ / C
399 Evaluate Division Medium C++
404 Sum of Left Leaves Easy C++
409 Longest Palindrome Easy C++
412 Fizz Buzz Easy C++ / C
414 Third Maximum Number Easy C++
435 Non-overlapping Intervals Medium C++
436 Find Right Interval Medium C++
437 Path Sum III Medium C++
442 Find All Duplicates in an Array Medium C++
450 Delete Node in a BST Medium C++
459 Repeated Substring Pattern Easy C++
470 Implement Rand10() Using Rand7() Medium C++
495 Teemo Attacking Medium C++ / C
497 Random Point in Non-overlapping Rectangles Medium C++
520 Detect Capitals Easy C++
654 Maximum Binary Tree Medium C++
701 Insert into a Binary Search Tree Medium C++
705 Design HashSet Easy C++
713 Subarray Product Less Than K Medium C++
763 Partition Labels Medium C++ / C
771 Jewels and Stones Easy C++
814 Binary Tree Pruning Medium C++
824 Goat Latin Easy C++
835 Image Overlap Medium C++
905 Sort Array By Parity Easy C++
921 Minimum Add to Make Parentheses Valid Medium C++
933 Number of Recent Calls Easy C++
938 Range Sum of BST Easy C++
949 Largest Time for Given Digits Easy C++
950 Reveal Cards In Increasing Orer Medium C++
951 Flip Equivalent Binary Trees Medium C++
967 Numbers With Same Consecutive Differences Medium C++
983 Minumum Cost For Tickets Medium C++
987 Vertical Order Traversal of a Binary Tree Medium C++
994 Rotting Oranges Medium C++
1008 Construct Binary Search Tree from Preorder Traversal Medium C++
1022 Sum of Root To Leaf Binary Numbers Easy C++
1028 Recover a Tree From Preorder Traversal Hard C++
1038 Binary Search Tree to Greater Sum Tree Medium C++
1041 Robot Bounded In Circle Medium C++
1094 Car Pooling Medium C++
1103 Distribute Candies to People Easy C++
1108 Defanging an IP Address Easy C++
1130 Minimum Cost Tree From Leaf Values Medium C++
1161 Maximum Level Sum of a Binary Tree Medium C++
1221 Split a String in Balanced Strings Medium C++
1281 Subtract the Product and Sum of Digits of an Integer Easy C++
1286 Iterator for Combination Medium C++
1290 Convert Binay Number in a Linked List to Integer Easy C++
1291 Sequential Digits Medium C++
1295 Find Numbers with Even Number of Digits Easy C++
1302 Deepest Leaves Sum Medium C++
1305 All elements in Two Binary Search Trees Medium C++ / C
1325 Delete Leaves With a Given Value Medium C++
1329 Sort the Matrix Diagonally Medium C++
1342 Number of Steps to Reduce a Number to Zero Easy C++
1365 How Many Numbers Are Smaller Than the Current Number Easy C++
1402 Reducing Dishes Hard C++
1431 Kids With the Greatest Number of Candies Easy C++
1470 Shuffle the Array Easy C++
1480 Running Sum of 1d Array Easy C++
1512 Number of Good Pairs Easy C++
1528 Shuffle String Easy C++