slt

Solution1 双指针

  • 时间复杂度 $O(n^2)$

  • 空间复杂度 $O(1)$

对暴力破解的优化

Solution2 DP

dp[i] represents number of satisfied sub-arrays ends with i, so answer will be sum of dp

Last updated