classSolution { private: boolisOk(vector<int>& nums, int l, int r){ int last = 0; for (int i = 0; i < nums.size(); i++) { if (l <= i && i <= r) { continue; } if (nums[i] <= last) { returnfalse; } last = nums[i]; } returntrue; } public: intincremovableSubarrayCount(vector<int>& nums){ int ans = 0; for (int l = 0; l < nums.size(); l++) { for (int r = l; r < nums.size(); r++) { ans += isOk(nums, l, r); } } return ans; } };
funcisOk(nums []int, l int, r int)int { last := 0 for i := 0; i < len(nums); i++ { if l <= i && i <= r { continue } if nums[i] <= last { return0 } last = nums[i] } return1 }
funcincremovableSubarrayCount(nums []int)int { ans := 0 for l := 0; l < len(nums); l++ { for r := l; r < len(nums); r++ { ans += isOk(nums, l, r) } } return ans }
classSolution { privatebooleanisOk(int[] nums, int l, int r) { intlast=0; for (inti=0; i < nums.length; i++) { if (l <= i && i <= r) { continue; } if (nums[i] <= last) { returnfalse; } last = nums[i]; } returntrue; }
publicintincremovableSubarrayCount(int[] nums) { intans=0; for (intl=0; l < nums.length; l++) { for (intr= l; r < nums.length; r++) { ans += isOk(nums, l, r) ? 1 : 0; } } return ans; } }
classSolution: defisOk(self, l: int, r: int) -> bool: last = 0 for i inrange(len(self.nums)): if l <= i <= r: continue ifself.nums[i] <= last: returnFalse last = self.nums[i] returnTrue
defincremovableSubarrayCount(self, nums: List[int]) -> int: self.nums = nums ans = 0 for l inrange(len(nums)): for r inrange(l, len(nums)): ans += self.isOk(l, r) return ans