// 参考了:https://discuss.leetcode.com/topic/51893/two-solutions-one-is-dp-the-other-is-greedy-8-lines
// 另有:https://discuss.leetcode.com/topic/51946/very-simple-java-solution-with-detail-explanation class Solution {
public:
int wiggleMaxLength(vector<int>& nums) {
int up = , down = ;
if (nums.size() <= ) {
return nums.size();
}
for (int i=; i<nums.size(); ++i) {
if (nums[i] < nums[i-]) {
down = up + ;
}
else if (nums[i] > nums[i-]) {
up = down + ;
}
}
return max(up, down);
}
};

wiggle-subsequence的更多相关文章

  1. Week13 - 376. Wiggle Subsequence

    Week13 - 376. Wiggle Subsequence A sequence of numbers is called a wiggle sequence if the difference ...

  2. 【LeetCode】376. Wiggle Subsequence 解题报告(Python)

    [LeetCode]376. Wiggle Subsequence 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.c ...

  3. [LeetCode] Wiggle Subsequence 摆动子序列

    A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...

  4. Leetcode 376. Wiggle Subsequence

    本题要求在O(n)时间内求解.用delta储存相邻两个数的差,如果相邻的两个delta不同负号,那么说明子序列摇摆了一次.参看下图的nums的plot.这个例子的答案是7.平的线段部分我们支取最左边的 ...

  5. 376. Wiggle Subsequence

    A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...

  6. LeetCode 376. Wiggle Subsequence 摆动子序列

    原题 A sequence of numbers is called a wiggle sequence if the differences between successive numbers s ...

  7. [Swift]LeetCode376. 摆动序列 | Wiggle Subsequence

    A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...

  8. [Leetcode 376]摇摆序列 Wiggle Subsequence

    [题目] A sequence of numbers is called a wiggle sequence if the differences between successive numbers ...

  9. 376 Wiggle Subsequence 摆动序列

    A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...

  10. 【Leetcode】376. Wiggle Subsequence

    Description: A sequence of numbers is called a wiggle sequence if the differences between successive ...

随机推荐

  1. 使用VisualStudio2015开发QT项目

    一直习惯用VS,做QT项目时,不停的来回切IDE有些不方便.研究了一下QT的编译. 实际QT编译的机制和cmake是相同的,QT的IDE使用pro文件进行项目管理.QMake通过解析pro工程文件,生 ...

  2. HDU - 2199 Can you solve this equation? 二分 简单题

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  3. Java工具类之浮点精确计算

    public class Arith { // 默认除法运算精度 private static final int DEF_DIV_SCALE = 10; // 构造器私有,让这个类不能实例化 pri ...

  4. JAVAEE——宜立方商城02:服务中间件dubbo、工程改造为基于soa架构、商品列表实现

    1. 学习计划 第二天:商品列表功能实现 1.服务中间件dubbo 2.工程改造为基于soa架构 3.商品列表查询功能实现. 2. 将工程改造为SOA架构 2.1. 分析 由于宜立方商城是基于soa的 ...

  5. Linux-CentOs7-svn安装及钩子配置

    做个svn的教程 首先进入test目录下,新建一个svn目录,准备做svn测试cd /testmkdir svncd svn然后使用yum安装svn,这里就不使用编译安装了,这玩意只要能用就行,版本无 ...

  6. [leetcode sort]147. Insertion Sort List

    Sort a linked list using insertion sort. 利用插入排序对一个链表进行排序 思路和数组中的插入排序一样,不过每次都要从链表头部找一个合适的位置,而不是像数组一样可 ...

  7. UNP学习总结(二)

    本文是UNP复习系列的第二篇,主要包括了以下几个内容 UNIX系统下5种I/O模型 阻塞.非阻塞,同步.异步 epoll函数用例 一.Unix下的五种可用I/O模型 阻塞式I/O模型 阻塞式I/O是最 ...

  8. jQuery中bind,live,delegate,on的区别

    bind(),live()都是调用on()函数,只不过传递的参数不同. 一.$(selector).bind(event,data,fn); $('#J_btn').bind('click',func ...

  9. java 反编译 android 反编译

    1. jad http://varaneckas.com/jad/jad158e.linux.intel.zip  下载jad, 给jad运行权限 ,运行 chmod a+x ./jad ./jad ...

  10. zookeeper【1】配置管理

    为什么要用统一配置? 我们做项目时用到的配置比如数据库配置等...我们都是写死在项目里面,如果需要更改,那么也是的修改配置文件然后再投产上去,那么问题来了,如果做集群的呢,有100台机器,这时候做修改 ...