leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 5684438eea23a066e6c3d856cfa1725a3c1588df
parent 3607f823852dd0645194fc2a764bf69ad2c891c7
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat,  4 Feb 2023 12:33:14 +0100

Data Structure II: Day 1

Diffstat:
AProblems/0169.cpp | 10++++++++++
MREADME.md | 1+
2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/Problems/0169.cpp b/Problems/0169.cpp @@ -0,0 +1,10 @@ +class Solution { +public: + int majorityElement(const vector<int> &nums) { + unordered_map<int, unsigned> um; + for (int n : nums) um[n]++; + for (auto [k, v] : um) + if (v > (nums.size() / 2)) return k; + return -1; + } +}; diff --git a/README.md b/README.md @@ -116,6 +116,7 @@ for solving problems. | 0160 | Easy | [Intersection of Two Linked Lists](Problems/0160.cpp) | | 0164 | Hard | [Maximum Gap](Problems/0164.cpp) | | 0167 | Medium | [Two Sum II - Input Array Is Sorted](Problems/0167.cpp) | +| 0169 | Easy | [Majority Element](Problems/0169.cpp) | | 0173 | Medium | [Binary Search Tree Iterator](Problems/0173.cpp) | | 0189 | Medium | [Rotate Array](Problems/0189.cpp) | | 0190 | Easy | [Reverse Bits](Problems/0190.cpp) |