leetcode

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

commit b5bc795531b91aee6dd5d6e6652aa4f8efccdeeb
parent e4c546d8852c1f9f8a06571a723ea2b3346ac4f9
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Tue, 25 Jul 2023 21:02:32 +0200

Random Problem

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

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


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

@@ -0,0 +1,15 @@
class Solution {
public:
int peakIndexInMountainArray(const vector<int> &arr) {
int low = 1, high = arr.size() - 2;
while (low <= high) {
int mid = low + (high - low) / 2;
if (arr[mid - 1] < arr[mid] && arr[mid] > arr[mid + 1]) return mid;
if (arr[mid - 1] < arr[mid])
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
};

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

@@ -366,6 +366,7 @@ for solving problems. | 0841 | Medium | [Keys and Rooms](Problems/0841.cpp) | | 0844 | Easy | [Backspace String Compare](Problems/0844.cpp) | | 0851 | Medium | [Loud and Rich](Problems/0851.cpp) |
| 0852 | Medium | [Peak Index in a Mountain Array](Problems/0852.cpp) |
| 0853 | Medium | [Car Fleet](Problems/0853.cpp) | | 0859 | Easy | [Buddy Strings](Problems/0859.cpp) | | 0863 | Medium | [All Nodes Distance K in Binary Tree](Problems/0863.cpp) |