首页 > TAG信息列表 > Turbulent
No.286 - [978] Longest Turbulent Subarray - 简单动态规划
/* * @lc app=leetcode id=978 lang=cpp * * [978] Longest Turbulent Subarray */ // @lc code=start class Solution { public: int maxTurbulenceSize(vector<int>& arr) { int N = arr.size(); if(N<=1){ return N;[LeetCode] 978. Longest Turbulent Subarray
Given an integer array arr, return the length of a maximum size turbulent subarray of arr. A subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray. More formally, a subarray [arr[i], arr[i + 1], ..., a978. Longest Turbulent Subarray
仅供自己学习 思路: 1.很明显,又是滑动窗口的题,只要 if判断能满足 ><,或<>就让右指针右移一个元素,并且记录长度 right-left+1。如果不满足则 left = right,再重复上述步骤 代码: 1 class Solution { 2 public: 3 int maxTurbulenceSize(vector<int>& arr) { 4 i