-
Recent Posts
Recent Comments
Archives
Categories
Meta
Monthly Archives: December 2019
Leetcode 23: Merge k Sorted Lists
There are a few different ways to solve this. I found the easiest way was to do a merge k-1 times. So you merge the first two lists. Then you merge that merged list with list 3. And repeat that … Continue reading
Leetcode 10: Regular Expression Matching
The Kleene stars (the * wildcard character for regular expressions) make this difficult. We can’t just gobble up all the wildcard matching characters, otherwise subsequent matches might not work. One way to solve this is by recursing every possibility, so … Continue reading
Leetcode 4: Median of Two Sorted Arrays
Let’s call our two arrays A and B, where they have sizes a and b. A key insight is that we need to partition both arrays such that the left of both will be the same size as the right … Continue reading
Trie Data Structure (Prefix Tree)
Use a TrieNode class that has a next member which is an array of 26 TrieNode pointers that represents a pointer to TreeNode object for each of 26 letters in the alphabet. We initialise these TrieNode pointers to NULL. We … Continue reading
Leetcode 188: Best Time to Buy and Sell Stock IV
To solve this we can use Dynamic Programming to gradually build upon previous solutions for t-1 transactions. The simplest to understand solution uses O(n²k) time and O(nk) space. We can optimise the time to O(nk) and space to O(n). The … Continue reading