leetcode

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

commit 56c5046c13a423e9e07576b7190eca56d0fb93ff
parent 0617187c45cd5f62959e7ea8a8c917c0b5457582
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Mon, 11 Dec 2023 21:16:55 +0000

Daily Problem

Diffstat:
A Problems/1287.cpp | ++++++++++++
M README.md | +

2 files changed, 13 insertions(+), 0 deletions(-)


diff --git a/ Problems/1287.cpp b/ Problems/1287.cpp

@@ -0,0 +1,12 @@
class Solution {
public:
int findSpecialInteger(vector<int> &arr) {
const int n = size(arr), quarter = n / 4;
for (const int candidate : {arr[n / 4], arr[n / 2], arr[3 * n / 4]}) {
const int left = lower_bound(begin(arr), end(arr), candidate) - begin(arr);
const int right = upper_bound(begin(arr), end(arr), candidate) - begin(arr);
if (right - left > quarter) return candidate;
}
return -1;
}
};

diff --git a/ README.md b/ README.md

@@ -602,6 +602,7 @@ for solving problems. | 1280 | Easy | [Students and Examinations](Problems/1280.cpp) | | 1282 | Medium | [Group the People Given the Group Size They Belong To](Problems/1282.cpp) | | 1286 | Medium | [Iterator for Combination](Problems/1286.cpp) |
| 1287 | Easy | [Element Appearing More Than 25% In Sorted Array](Problems/1287.cpp) |
| 1290 | Easy | [Convert Binary Number in a Linked List to Integer](Problems/1290.cpp) | | 1291 | Medium | [Sequential Digits](Problems/1291.cpp) | | 1302 | Medium | [Deepest Leaves Sum](Problems/1302.cpp) |