第六十六天:力扣376题,摆动序列
地址:leetcode-cn.com/problems/wi…
思路:动态规划,嗯,就这样,开始使用ts来写代码
function wiggleMaxLength(nums: number[]): number {
if (nums.length < 2)
{
return nums.length;
}
let a:number = 1;
let b:number = 1;
for(let i:number = 0; i < nums.length; i++)
{
if(nums[i] < nums[i + 1])
{
a = b + 1;
}
if(nums[i] > nums[i + 1])
{
b = a + 1;
}
}
return Math.max(a, b);
};
执行用时:88 ms, 在所有 TypeScript 提交中击败了50.00%的用户
内存消耗:40.1 MB, 在所有 TypeScript 提交中击败了12.50%的用户