TopKFrequentElements

TopKFrequentElements Difficulty: Medium Topics: Hash Table, Heap, Frequency Counting Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Approach This problem asks us to find the k most frequent elements. We first use an unordered_map to count the frequency of each element. Then we use a min-heap of size k to maintain the current top-k elements. When the heap size exceeds k, we remove the smallest element. Finally, we obtain a list of size k that contains the top-k elements. ...

March 2, 2026 · 1 分鐘 · yihan-lee

C++ STL Cheatsheet

C++ STL Cheatsheet STL (Standard Template Library) provides generic containers and algorithms for C++ development. This note summarizes commonly used containers, typical usage patterns, and pitfalls. Headers (common) #include <vector> #include <array> #include <string> #include <deque> #include <list> #include <forward_list> #include <queue> #include <stack> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <algorithm> #include <utility> #include <tuple> #include <bitset> Vector Dynamic array with contiguous memory. vector<int> v = {1,2,3}; v.push_back(4); v.emplace_back(5); int x = v[0]; v.pop_back(); Notes Random access: O(1) Insert/erase in middle: O(n) reserve(n) reduces reallocations Iterator invalidation: reallocation invalidates all iterators/pointers/references Array Fixed-size array (stack-friendly, no dynamic allocation). ...

March 1, 2026 · 5 分鐘 · yihan-lee

hugo markdown syntax pratice and command list

Markdown syntax # Title ## Title ### Title #### Title ##### Title ###### Title bold italic strike blockquote struct Packet { uint32_t seq; uint32_t ack; }; Euler: $e^{i\pi} + 1 = 0$ graph TD SoC --> MCU_A SoC --> MCU_B Feature Status RSS OK Math OK Mermaid OK Hugo commands Local host develop hugo server -D Create Post 單篇文章 hugo new posts/hello.md Page Bundle hugo new posts/hello/index.md 圖片放 content/posts/hello/img/{img_name}.{img_extension} ...

February 28, 2026 · 1 分鐘 · yihan-lee