标签:
// 参考了: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 = 1, down = 1; if (nums.size() <= 1) { return nums.size(); } for (int i=1; i<nums.size(); ++i) { if (nums[i] < nums[i-1]) { down = up + 1; } else if (nums[i] > nums[i-1]) { up = down + 1; } } return max(up, down); } };
标签:
原文地址:http://www.cnblogs.com/charlesblc/p/5725632.html