改動一個數字變成遞增數列

leetcode:https://leetcode.com/problems/non-decreasing-array/git

給定一個長度爲 n 的整數數組,你的任務是判斷在最多改變 1 個元素的狀況下,該數組可否變成一個非遞減數列。github

咱們是這樣定義一個非遞減數列的: 對於數組中全部的 i (1 <= i < n),知足 array[i] <= array[i + 1]數組

示例 1:code

輸入: [4,2,3]
輸出: True
解釋: 你能夠經過把第一個4變成1來使得它成爲一個非遞減數列。

示例 2:blog

輸入: [4,2,1]
輸出: False
解釋: 你不能在只改變一個元素的狀況下將其變爲非遞減數列。

說明:  n 的範圍爲 [1, 10,000]。leetcode

簡潔一點:get

git:https://github.com/woshiyexinjie/leetcode-xinit

相關文章
相關標籤/搜索