leetcode

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

commit a2abe19f37631d797f036ebb850fe256cc4f8f11
parent 8cff7477f0f8e680eecea787a813db39875fe56d
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Tue,  4 Jun 2024 17:52:59 +0200

1 Random Problem

Diffstat:
AProblems/2401.cpp | 15+++++++++++++++
MREADME.md | 1+
2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/Problems/2401.cpp b/Problems/2401.cpp @@ -0,0 +1,15 @@ +class Solution { + public: + int longestNiceSubarray(const vector<int> &nums) const { + int res = 0, used = 0, j = 0; + + for (int i = 0; i < size(nums); i++) { + while (used & nums[i]) + used ^= nums[j++]; + used |= nums[i]; + res = max(res, i - j); + } + + return res + 1; + } +}; diff --git a/README.md b/README.md @@ -1119,6 +1119,7 @@ for solving problems. | 2391 | Medium | [Minimum Amount of Time to Collect Garbage](Problems/2391.cpp) | | 2396 | Medium | [Strictly Palindromic Number](Problems/2396.cpp) | | 2397 | Medium | [Maximum Rows Covered by Columns](Problems/2397.cpp) | +| 2401 | Medium | [Longest Nice Subarray](Problems/2401.cpp) | | 2402 | Hard | [Meeting Rooms III](Problems/2402.cpp) | | 2405 | Medium | [Optimal Partition of String](Problems/2405.cpp) | | 2410 | Medium | [Maximum Matching of Players With Trainers](Problems/2410.cpp) |