978. Longest Turbulent Subarray——array
生活随笔
收集整理的這篇文章主要介紹了
978. Longest Turbulent Subarray——array
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目分析:不是用動(dòng)態(tài)規(guī)劃,python3沒(méi)有了cmp函數(shù)
class Solution(object):def cmp(self, a, b):if a > b:return 1if a < b:return -1if a == b:return 0def removeDuplicates(self, A):""":type nums: List[int]:rtype: int"""N = len(A)ans = 1anchor = 0for i in range(1, N):c = self.cmp(A[i-1], A[i])if i == N-1 or c * self.cmp(A[i], A[i+1]) != -1:ans = max(ans, i - anchor + 1)anchor = ireturn ans總結(jié)
以上是生活随笔為你收集整理的978. Longest Turbulent Subarray——array的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 数据库系统笔记4: ER模型
- 下一篇: 煤炭行业智能SRM系统:实现供应商可视化