Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 51ffdc1

Browse files
2970. Count the Number of Incremovable Subarrays I
1 parent a6ea585 commit 51ffdc1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
3+
// Solution by Sergey Leschev
4+
// 2970. Count the Number of Incremovable Subarrays I
5+
6+
func incremovableSubarrayCount(_ nums: [Int]) -> Int {
7+
var ans = 0
8+
9+
for i in 0..<nums.count {
10+
for j in i..<nums.count {
11+
var last = -1
12+
var flag = true
13+
14+
for k in 0..<nums.count {
15+
if k >= i && k <= j {
16+
continue
17+
}
18+
19+
if last >= nums[k] {
20+
flag = false
21+
break
22+
}
23+
24+
last = nums[k]
25+
}
26+
27+
if flag {
28+
ans += 1
29+
}
30+
}
31+
}
32+
33+
return ans
34+
}
35+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /