/leetcode

My LeetCode solutions.

Primary LanguagePythonMIT LicenseMIT

LeetCode Progress

My solutions to problems on LeetCode (https://leetcode.com/) using Java or Ruby sometimes.

Every solution has its corresponding question number, name, general idea to solve the problem and different methods used written in the top comment.

Current Solutions

Array

Status No. Title Language Time Space Note
1 Two Sum Java/Ruby O(n) O(n) HashMap
122 Best Time to Buy and Sell Stock II Java O(n) O(1) Accumulation of profit, Peak-valley is overkill but can be useful sometime.
136 Single Number Java O(n) O(1) XOR is always the trick!
283 Move Zeroes Java O(n) O(1) Two pointers, best & worst cases help understand
412 FizzBuzz Java O(n) O(n) LinkedList

Math

Status No. Title Language Time Space Note
171 Excel Sheet Column Number Java O(n) O(1) Base 26 calculation

List

Status No. Title Language Time Space Note
237 Delete Node in a Linked List O(1) O(1) Java Without access to the previous node, replace current node with next node and delete the next node

String

Status No. Title Language Time Space Note
344 Reverse String Java O(n) O(n) Char array and String.valueOf()
387 First Unique Character in a String Java O(n) O(1) Bit vector counting the frequency of char

Tree

Status No. Title Language Time Space Note
104 Maximum Depth of Binary Tree Java O(n) O(n) With/without instance variable Top-bottom tree traversal

Bit Manipulation

Status No. Title Language Time Space Note
371 Sum of Two Integers Java O(n) O(n) Sum without carry by ^, carry by &

HashSet, HashTable

No. Title Language Time Space Note
136 Single Number Java HashSet
137 Single Number II Java HashSet
217 Contains Duplicate Java/Ruby HashSet
242 Valid Anagram Java HashMap

Binary Search

No. Title Language Note
278 First Bad Version Java

Binary Tree

No. Title Language Note
226 Invert Binary Tree Java

Two Pointers

No. Title Language Note
26 Remove Duplicates from Sorted Array Java
27 Remove Element Java

Not Yet Categorised

No. Title Language Note
198 House Robber Java
338 Counting Bits Java/Ruby
239 Sliding Window Maximum Java
344 Reverse String Java
347 Top K Frequent Elements Java