Posts

Showing posts from November, 2018

Design

705 Design HashSet Use BST tree to implement HashSet

Sort

349 Intersection of Two Arrays    (N) Sort both array nums1 and nums2 and call STL set_intersection to save result to nums1. create a set from nums1 beginning. create a vector of int out of the result set and return it. 242  Valid Anagram  (N) Solution 1: sort both the string s and t in ascending order. return s == t O(NlgN) time and O(1) space Solution 2: Use 2 hash map freq1 and freq2 to save the chars frequency of both s and t return the freq1 == freq2 350  Intersection of Two Arrays II        (Y) Solution 1: same with 349 Solution 2: Use hash Map to count the frequency of each number in the first array. In the second loop, loop each element in the second array, if freq[num]-- still > 0, add it to the result array, otherwise skip it. return the result array in the end. 524 Longest Word in Dictionary through Deleting     (Y)  Wihtout sorting: O((L + S) * D) = O(D(L + S)), O(L) space ...