打卡记录
统计移除递增子数组的数目 II(双指针)
链接
class Solution:def incremovableSubarrayCount(self, a: List[int]) -> int:n = len(a)i = 0while i < n - 1 and a[i] < a[i + 1]:i += 1if i == n - 1: # 每个非空子数组都可以移除return n * (n + 1) // 2ans = i + 2j = n - 1while j == n - 1 or a[j] < a[j + 1]:while i >= 0 and a[i] >= a[j]:i -= 1ans += i + 2j -= 1return ans