当前位置:网站首页>leetcode 665. Non-decreasing Array 非递减数列(中等)
leetcode 665. Non-decreasing Array 非递减数列(中等)
2022-07-31 18:00:00 【InfoQ】
一、题目大意
- n == nums.length
- 1 <= n <= 104
- -105 <= nums[i] <= 105
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public boolean checkPossibility(int[] nums) {
int cnt = 1;
for (int i = 1; i < nums.length; i++) {
if (nums[i] < nums[i - 1]) {
if (cnt == 0) {
return false;
}
cnt--;
if (i == 1) {
nums[i - 1] = nums[i];
} else if (nums[i] >= nums[i - 2]) {
nums[i - 1] = nums[i];
} else {
nums[i] = nums[i - 1];
}
}
}
return true;
}
}
四、总结小记
- 2022/7/31 今天天气很闷热呀
边栏推荐
猜你喜欢

35道MySQL面试必问题图解,这样也太好理解了吧

Chinese encoding Settings and action methods return values

Flex布局详解

研发过程中的文档管理与工具

基于WPF重复造轮子,写一款数据库文档管理工具(一)

All-platform GPU general AI video supplementary frame super-score tutorial

35 MySQL interview questions and diagrams, this is also easy to understand

AcWing 1282. Search Keyword Problem Solution ((AC Automata) Trie+KMP)+bfs)

A common method and the use of selenium

你辛辛苦苦写的文章可能不是你的原创
随机推荐
mysql的备份表的几种方法
go mode tidy出现报错go warning “all“ matched no packages
Flutter gets the height of the status bar statusbar
MySQL---sort and pagination
【Yugong Series】July 2022 Go Teaching Course 022-Dictionary of Go Containers
保证接口数据安全的10种方式
LevelSequence源码分析
Jiuqi ny3p series voice chip replaces the domestic solution KT148A, which is more cost-effective and has a length of 420 seconds
这位985教授火了!当了10年博导,竟无一博士毕业!
杰理语音芯片ic玩具芯片ic的介绍_AD14NAD15N全系列开发
【愚公系列】2022年07月 Go教学课程 022-Go容器之字典
21.支持向量机—核函数的介绍
【luogu P8326】Fliper (Graph Theory) (Construction) (Eulerian Circuit)
Go1.18升级功能 - 模糊测试Fuzz 从零开始Go语言
All-platform GPU general AI video supplementary frame super-score tutorial
Cache and Database Consistency Solutions
【pytorch】pytorch 自动求导、 Tensor 与 Autograd
无主复制系统(3)-Quorum一致性的局限性
【愚公系列】2022年07月 Go教学课程 020-Go容器之数组
Masterless replication system (2) - read and write quorum