2024-03-02 2024-08-05 problem 几秒读完 (大约95个字) 0次访问lc2369.检查数组是否存在有效划分题目链接: 题解 简单 dp 参考代码 12345678910111213141516171819202122232425262728293031323334353637/* * @lc app=leetcode.cn id=2369 lang=cpp * * [2369] 检查数组是否存在有效划分 */// @lc code=startclass Solution {public: bool validPartition(vector<int>& nums) { int ok[112345]; memset(ok, 0, sizeof ok); int n = nums.size(); for(int i=1;i<n;i++) { if(nums[i-1] == nums[i]) { if(i==1||ok[i-2]) ok[i] = 1; } if(i>=2) { if(nums[i-2] == nums[i-1] && nums[i-1] == nums[i]) { if(i==2||ok[i-3]) ok[i] = 1; } if(nums[i-2] + 1 == nums[i-1] && nums[i-1] +1 == nums[i]) { if(i==2||ok[i-3]) ok[i] = 1; } } } return ok[n-1]; }};// @lc code=end lc2369.检查数组是否存在有效划分https://blog.xiang578.com/problem/lc2369.html作者Ryen Xiang发布于2024-03-02更新于2024-08-05许可协议 LeetCode, Dynamic Programming