Movatterモバイル変換


[0]ホーム

URL:


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

Commit540318b

Browse files
authored
Create Longest Strictly Increasing or Strictly Decreasing Subarray.java
1 parentd8afeb2 commit540318b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
classSolution {
2+
publicintlongestMonotonicSubarray(int[]nums) {
3+
intmax =1;
4+
intidx =0;
5+
intn =nums.length;
6+
while (idx <n) {
7+
if (idx ==n -1 ||nums[idx +1] ==nums[idx]) {
8+
idx++;
9+
continue;
10+
}
11+
booleanincrease =nums[idx +1] >nums[idx];
12+
intstart =idx;
13+
while (idx +1 <n && (
14+
(increase &&nums[idx +1] >nums[idx]) ||
15+
(!increase &&nums[idx +1] <nums[idx]))) {
16+
idx++;
17+
}
18+
max =Math.max(max,idx -start +1);
19+
}
20+
returnmax;
21+
}
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp