์ „์ฒด ๊ธ€

LeetCode ๐Ÿ”๏ธ/Heap

295. Find Median from Data Stream

Description: Solution: In the Heap, Add elements, remove elements: O(logn), Find Max/Min elements: O(1) ex) 1. add(3): Add to small heap[O(logn)] 2. add(2): Add to small heap, small heap: 2, large heap: 0, so we find the maximum value of small heap[O(1)], and add it to large heap(O(logn)] 3. add(7): Add to small heap[O(logn)], 7 is bigger than 3, so find the max[O(1)], move to large heap[O(logn)..

LeetCode ๐Ÿ”๏ธ/Heap

347. Top K Frequent Elements

Description: Solution: count is the dictionary for heap. We go through the nums, and counting. If the number doesn't exist, get(0). And then, from hash table, we put the values in freq[[]] to see how many counts they have. Since the freq[[]] is descending order, we go through reverse order. We put the highest count to lowest count. We append the higest number of count in res[]. End the loop if w..

LeetCode ๐Ÿ”๏ธ/Graph

32. Graph Valid Tree

Description: Solution:

LeetCode ๐Ÿ”๏ธ/Graph

269. Alien Dictionary

Descripition: Solution:

LeetCode ๐Ÿ”๏ธ/Graph

128. Longest Consecutive Sequence

Description: Solution: Sorthing is O(nlogn), so we need a solution for O(n) if (n - 1) not in numSet, it would be the first start point of sequence. In while loop, we keep add the length by 1 to see how long the sequence is. And then, return the longest sequence. Time Complexity: O(n) Space Complexity: O(n)

LeetCode ๐Ÿ”๏ธ/Graph

417. Pacific Atlantic Water Flow

Description: Solution: Time Complexity: O(nm)

LeetCode ๐Ÿ”๏ธ/Graph

207. Course Schedule

Description: Solution:

LeetCode ๐Ÿ”๏ธ/Graph

133. Clone Graph

Description: Solution: Time Complexity: O(n)

KB0129
To The Top ๐Ÿ—ป