当前位置:网站首页>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?
边栏推荐
猜你喜欢
随机推荐
2022年全国职业院校技能大赛网络安全 B模块 B-1任务一:主机发现与信息收集 国赛原题
卷起来!阿里高工携 18 位高级架构师耗时 57 天整合的 1658 页面试总结
这几个常用 alias,带你高效做事(下)
手动输入班级人数及成绩求总成绩和平均成绩?
nxp官方uboot移植到野火开发板PRO(修改LCD部分和网络部分)
win10安装及配置Gradle
XSS online shooting range---haozi
C. Fishingprince Plays With Array--Codeforces Global Round 21
一文带你了解软件测试是干什么的?薪资高不高?0基础怎么学?
肝完 Alibaba 这份面试通关宝典,我成功拿下今年第 15 个 Offer
XSS线上靶场---prompt
template string
LeetCode_位数统计_中等_400.第 N 位数字
461. 汉明距离
XSS测试
ES、Kibana 8.0安装
PyCharm函数自动添加注释无参数问题
从0到1看支付
研究Fabric中Etcd的Raft应用
CAS:1192802-98-4_UV 裂解的生物素-PEG2-叠氮









