本文主要是介绍Golang | Leetcode Golang题解之第376摆动序列,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
题解:
int wiggleMaxLength(int* nums, int numsSize) {if (numsSize < 2) {return numsSize;}int prevdiff = nums[1] - nums[0];int ret = prevdiff != 0 ? 2 : 1;for (int i = 2; i < numsSize; i++) {int diff = nums[i] - nums[i - 1];if ((diff > 0 && prevdiff <= 0) || (diff < 0 && prevdiff >= 0)) {ret++;prevdiff = diff;}}return ret;
}
这篇关于Golang | Leetcode Golang题解之第376摆动序列的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!