Skip to content

Commit 8718f23

Browse files
authored
Create Solution.java
1 parent c029a07 commit 8718f23

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int wiggleMaxLength(int[] nums) {
3+
if (nums.length < 2) {
4+
return nums.length;
5+
}
6+
int up = 1;
7+
int down = 1;
8+
for (int i = 1; i < nums.length; ++i) {
9+
if (nums[i] > nums[i - 1]) {
10+
up = down + 1;
11+
} else if (nums[i] < nums[i - 1]) {
12+
down = up + 1;
13+
}
14+
}
15+
return Math.max(up, down);
16+
}
17+
}

0 commit comments

Comments
 (0)