当前位置:网站首页>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 今天天气很闷热呀
边栏推荐
- adb shell error error: device unauthorized
- Write a database document management tool based on WPF repeating the wheel (1)
- Flex布局详解
- Taobao/Tmall get Taobao password real url API
- This 985 professor is on fire!After 10 years of Ph.D. supervisor, no one has graduated with a Ph.D.!
- mysql的备份表的几种方法
- 这位985教授火了!当了10年博导,竟无一博士毕业!
- 研发过程中的文档管理与工具
- UserAgent 解析
- ThreadLocal
猜你喜欢
flyway的快速入门教程
IP协议从0到1
这位985教授火了!当了10年博导,竟无一博士毕业!
[pytorch] pytorch automatic derivation, Tensor and Autograd
杰理语音芯片ic玩具芯片ic的介绍_AD14NAD15N全系列开发
flowable工作流所有业务概念
Smart Trash Can (8) - Infrared Tube Sensor (Raspberry Pi pico)
Huawei mobile phone one-click to open "maintenance mode" to hide all data and make mobile phone privacy more secure
阿里三面:MQ 消息丢失、重复、积压问题,如何解决?
程序员如何学习开源项目,这篇文章告诉你
随机推荐
淘宝/天猫获得淘口令真实url API
GP 6 overall architecture study notes
Chinese encoding Settings and action methods return values
Cache and Database Consistency Solutions
Multi-datacenter operation and detection of concurrent writes
IP protocol from 0 to 1
LevelSequence源码分析
架构师04-应用服务间加密设计和实践
这位985教授火了!当了10年博导,竟无一博士毕业!
【NLP】什么是模型的记忆力!
浅谈网络安全之算法安全
2022年Android 面经总结(附含面试题 | 源码 | 面试资料)
Bika LIMS 开源LIMS集—— SENAITE的使用(检测流程)
抖音根据关键词取视频列表 API
spark报错OutOfMemory「建议收藏」
MySQL---多表查询
MySQL---Create and manage databases and data tables
ThreadLocal
获取抖音视频详情 API
Get Douyin Video Details API