-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
37 lines (36 loc) · 867 Bytes
/
Solution.cs
File metadata and controls
37 lines (36 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class Solution
{
public int IncremovableSubarrayCount(int[] nums)
{
int n = nums.Length;
int ret = 0;
for (int i = 0; i < n; i++)
{
for (int j = i; j < n; j++)
{
if (IsIncreasing(nums, i, j))
{
ret++;
}
}
}
return ret;
}
bool IsIncreasing(int[] nums, int left, int right)
{
int n = nums.Length;
for (int i = 0; i + 1 < left; i++)
{
if (nums[i] >= nums[i + 1]) return false;
}
for (int i = right + 1; i + 1 < n; i++)
{
if (nums[i] >= nums[i + 1]) return false;
}
if (left - 1 >= 0 && right + 1 < n)
{
return nums[left - 1] < nums[right + 1];
}
return true;
}
}