#2354. 最长上升子序列变种
最长上升子序列变种
No testdata at current.
Background
最长上升子序列变种
Description
给定一个长度为 n 的整数序列 nums,请你找出其中最长的摆动子序列的长度。摆动子序列是指一个连续或不连续的子序列,其中相邻元素的差值正负交替出现(即先增后减、再增再减…… 或先减后增、再减再增……)。 例如: 序列 [1,7,4,9,2,5] 的最长摆动子序列是 [1,7,4,9,2],长度为 5; 序列 [1,2,3,4,5] 的最长摆动子序列长度为 2(任意两个相邻元素)。
Format
Input
Two integers x and y, satisfying .
Output
One integer, the sum of x and y.
Samples
6
1 7 4 9 2 5
5
Limitation
1s, 1024KiB for each test case. 实现时间复杂度为 O (n)、空间复杂度为 O (1) 的解法; 不能使用额外的数组存储中间状态