专栏名称: 每日一道算法题
学习算法是一种信仰,每天都需要坚持!
目录
相关文章推荐
算法与数学之美  ·  二级教授、大学原副校长,国务院特殊津贴获得者 ... ·  11 小时前  
算法与数学之美  ·  数学大家丘成桐主编的科普读物:中国孩子要培养 ... ·  11 小时前  
九章算法  ·  Cruise被迫裁员50%!高额遣散费打脸科 ... ·  2 天前  
九章算法  ·  一年被裁两次,一个底层码农的大落大起 ·  2 天前  
51好读  ›  专栏  ›  每日一道算法题

665. Non-decreasing Array

每日一道算法题  · 公众号  · 算法  · 2017-10-30 19:54

正文

Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.


We define an array is non-decreasing if array[I] <= array[I + 1] holds for every I (1 <= I < n).


Example 1:

Input: [4,2,3]

Output: True

Explanation: You could modify the first

4

to

1

to get a non-decreasing array.

Example 2:

Input: [4,2,1]

Output: False

Explanation: You can’t get a non-decreasing array by modify at most one element.

Note: The n belongs to [1, 10,000].


提示:提交代码后,需要用简洁的语言解释一下代码思路~ 谢谢


历史题目和总结见公众号「每日一道算法题」


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


小Fu讲解














请到「今天看啥」查看全文