leetcode

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

commit 71a3e588c3521c734449cd7da78bf462c5c8e65d
parent 997f1252e1dfce721a54792ed5ca3be273763d6b
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Thu, 10 Aug 2023 23:00:21 +0200

Daily Problem

Diffstat:
AProblems/0081.cpp | 24++++++++++++++++++++++++
MREADME.md | 3++-
2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/Problems/0081.cpp b/Problems/0081.cpp @@ -0,0 +1,24 @@ +class Solution { +public: + bool search(const vector<int> &nums, int target) { + int left = 0, right = nums.size() - 1; + while (left <= right) { + int mid = left + (right - left) / 2; + if (nums[mid] == target) return true; + if (nums[mid] == nums[left]) { + left++; + continue; + } + + bool pivotArr = nums[left] <= nums[mid]; + bool targetArr = nums[left] <= target; + if ((pivotArr ^ targetArr) ? (pivotArr) : (nums[mid] < target)) { + left = mid + 1; + } else { + right = mid - 1; + } + } + + return false; + } +}; diff --git a/README.md b/README.md @@ -99,6 +99,7 @@ for solving problems. | 0078 | Medium | [Subsets](Problems/0078.cpp) | | 0079 | Medium | [Word Search](Problems/0079.cpp) | | 0080 | Medium | [Remove Duplicates from Sorted Array II](Problems/0080.cpp) | +| 0081 | Medium | [Search in Rotated Sorted Array II](Problems/0081.cpp) | | 0082 | Medium | [Remove Duplicates from Sorted List II](Problems/0082.cpp) | | 0083 | Easy | [Remove Duplicates from Sorted List](Problems/0083.cpp) | | 0084 | Hard | [Largest Rectangle in Histogram](Problems/0084.cpp) | @@ -599,7 +600,7 @@ for solving problems. | 2368 | Medium | [Reachable Nodes With Restrictions](Problems/2368.cpp) | | 2374 | Medium | [Node With Highest Edge Score](Problems/2374.cpp) | | 2390 | Medium | [Removing Stars From a String](Problems/2390.cpp) | -| 2396 | Medium | [Strictly Palindromic Number](Problems/2396.cpp) +| 2396 | Medium | [Strictly Palindromic Number](Problems/2396.cpp) | | 2405 | Medium | [Optimal Partition of String](Problems/2405.cpp) | | 2421 | Medium | [Number of Good Paths](Problems/2421.cpp) | | 2439 | Medium | [Minimize Maximum of Array](Problems/2439.cpp) |