leetcode

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

commit e4c546d8852c1f9f8a06571a723ea2b3346ac4f9
parent 2231d61cbb2d0e5894bbb3ee04c8cb1194453a3b
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon, 24 Jul 2023 19:48:10 +0200

Random Problem

Diffstat:
AProblems/0274.cpp | 19+++++++++++++++++++
MREADME.md | 1+
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/Problems/0274.cpp b/Problems/0274.cpp @@ -0,0 +1,19 @@ +class Solution { + static int arr[5001]; + +public: + int hIndex(vector<int> &citations) { + memset(arr, 0x00, sizeof(arr)); + for (int n : citations) arr[n]++; + + int total = 0; + for (int i = 5000; i >= 0; i--) { + total += arr[i]; + if (total >= i) return i; + } + + return -1; + } +}; + +int Solution::arr[5001] = {0}; diff --git a/README.md b/README.md @@ -219,6 +219,7 @@ for solving problems. | 0263 | Easy | [Ugly Number](Problems/0263.cpp) | | 0264 | Medium | [Ugly Number II](Problems/0264.cpp) | | 0268 | Easy | [Missing Number](Problems/0268.cpp) | +| 0274 | Medium | [H-Index](Problems/0274.cpp) | | 0278 | Easy | [First Bad Version](Problems/0278.cpp) | | 0279 | Medium | [Perfect Squares](Problems/0279.cpp) | | 0283 | Easy | [Move Zeroes](Problems/0283.cpp) |