leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 556b8dd23c9d9f9e397d21470ce94d1bb23b33d4 |
parent | 1f1e18fa41a019e8aee4f354dbfb525653db6ba4 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Sun, 13 Aug 2023 20:33:00 +0200 |
Daily Problem
Diffstat:A | Problems/2369.cpp | | | ++++++++++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/Problems/2369.cpp b/Problems/2369.cpp
@@ -0,0 +1,28 @@
class Solution {
int8_t dp[100001];
public:
Solution() { memset(dp, 0xFF, sizeof(dp)); }
bool validPartition(const vector<int> &nums, int idx = 0) {
if (idx == nums.size()) return true;
if (idx == nums.size() - 1) return false;
if (dp[idx] != -1) return dp[idx];
if (nums[idx] == nums[idx + 1]) {
if (validPartition(nums, idx + 2)) return dp[idx] = true;
}
if (idx == nums.size() - 2) return dp[idx] = false;
if (nums[idx] == nums[idx + 1] && nums[idx] == nums[idx + 2]) {
if (validPartition(nums, idx + 3)) return dp[idx] = true;
}
if (nums[idx] + 1 == nums[idx + 1] && nums[idx] + 2 == nums[idx + 2]) {
if (validPartition(nums, idx + 3)) return dp[idx] = true;
}
return dp[idx] = false;
}
};
diff --git a/README.md b/README.md
@@ -600,6 +600,7 @@ for solving problems.
| 2359 | Medium | [Find Closest Node to Given Two Nodes](Problems/2359.cpp) |
| 2360 | Hard | [Longest Cycle in a Graph](Problems/2360.cpp) |
| 2368 | Medium | [Reachable Nodes With Restrictions](Problems/2368.cpp) |
| 2369 | Medium | [Check if There is a Valid Partition For The Array](Problems/2369.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) |