当前位置:网站首页>376. Wiggle Subsequence
376. Wiggle Subsequence
2022-08-03 21:29:00 【51CTO】
A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a wiggle sequence.
For example, [1,7,4,9,2,5] is a wiggle sequence because the differences (6,-3,5,-7,3) are alternately positive and negative. In contrast, [1,4,7,2,5] and [1,7,4,5,5] are not wiggle sequences, the first because its first two differences are positive and the second because its last difference is zero.
Given a sequence of integers, return the length of the longest subsequence that is a wiggle sequence. A subsequence is obtained by deleting some number of elements (eventually, also zero) from the original sequence, leaving the remaining elements in their original order.
Examples:
Follow up:
Can you do it in O(n) time?
边栏推荐
猜你喜欢
随机推荐
dataframe multi-level index replace index df.swaplevel(axis=1)
[kali-vulnerability scanning] (2.1) Nessus download and installation (on)
图神经网络怎么入门?一文带你了解图神经网络入门路径-GNN入门
E - Swap
Cross-end development technical reserve record
CC2530_ZigBee+华为云IOT:设计一套属于自己的冷链采集系统
C. Keshi Is Throwing a Party- Codeforces Global Round 17
2022年全国职业院校技能大赛网络安全 B模块 B-1任务一:主机发现与信息收集 国赛原题
聚焦开源与联合共创|麒麟软件出席开源峰会欧拉分论坛
Markdown syntax
一体化HTAP数据库如此难,为什么他们还要做?
shell编程基础
小朋友学C语言(3):整数、浮点数、字符
【kali-漏洞扫描】(2.1)Nessus下载安装(上)
Diazo Biotin-PEG3-DBCO|重氮化合物修饰生物素-三聚乙二醇-二苯并环辛炔
CAS:908007-17-0_Biotin-azide _生物素叠氮化物
卷起来!阿里高工携 18 位高级架构师耗时 57 天整合的 1658 页面试总结
IDaaS 是什么?一文说清它的价值
gtk实现图片旋转
主板设计中:网络变压器与RJ45网口之间应该保持什么样的距离?