【力扣】非递减数列

题目

思路

代码

python 复制代码
class Solution:
    def checkPossibility(self, nums: List[int]) -> bool:
        n =len(nums)
        flag=0
        for index,element in enumerate(nums):
            if index<=n-2:
                if flag==1:
                    if element>nums[index+1]:
                        return False
                elif element>nums[index+1]:
                    flag=1
                    if index!=0:
                        if nums[index-1]<=nums[index+1]:
                            nums[index]=nums[index-1]
                        else:
                            nums[index+1]=element
        return True
            
           
相关推荐
星火开发设计30 分钟前
枚举类 enum class:强类型枚举的优势
linux·开发语言·c++·学习·算法·知识
嘴贱欠吻!6 小时前
Flutter鸿蒙开发指南(七):轮播图搜索框和导航栏
算法·flutter·图搜索算法
张祥6422889046 小时前
误差理论与测量平差基础笔记十
笔记·算法·机器学习
踩坑记录6 小时前
leetcode hot100 2.两数相加 链表 medium
leetcode·链表
qq_192779877 小时前
C++模块化编程指南
开发语言·c++·算法
cici158748 小时前
大规模MIMO系统中Alamouti预编码的QPSK复用性能MATLAB仿真
算法·matlab·预编码算法
历程里程碑9 小时前
滑动窗口---- 无重复字符的最长子串
java·数据结构·c++·python·算法·leetcode·django
2501_9403152610 小时前
航电oj:首字母变大写
开发语言·c++·算法
CodeByV10 小时前
【算法题】多源BFS
算法
TracyCoder12310 小时前
LeetCode Hot100(18/100)——160. 相交链表
算法·leetcode