美文网首页
376. Wiggle Subsequence

376. Wiggle Subsequence

作者: becauseyou_90cd | 来源:发表于2018-07-26 06:11 被阅读0次

https://leetcode.com/problems/wiggle-subsequence/description/
subsequence代表数字间隔in array
解题思路:up and down represents greater and lesser.

代码:
class Solution {
public int wiggleMaxLength(int[] nums) {

    if(nums.length == 0) return 0;
    int up = 1;
    int down = 1;
    for(int i = 1; i < nums.length; i++){
        if(nums[i] > nums[i - 1]){
            up = down + 1;
        }else if(nums[i] < nums[i - 1]){
            down = up + 1;
        }
    }
    return Math.max(up, down);
}

}

相关文章

网友评论

      本文标题:376. Wiggle Subsequence

      本文链接:https://www.haomeiwen.com/subject/lprvmftx.html