力扣896

python 复制代码
bool isMonotonic(int* nums, int numsSize) {
    if (numsSize <= 1) {
        return true;
    }
    
    bool isIncreasing = true;
    bool isDecreasing = true;
    
    for (int i = 1; i < numsSize; i++) {
        if (nums[i] > nums[i - 1]) {
            isDecreasing = false;
        }
        if (nums[i] < nums[i - 1]) {
            isIncreasing = false;
        }
    }
    
    return isIncreasing || isDecreasing;
}
python 复制代码
class Solution:
    def isMonotonic(self, nums: List[int]) -> bool:
        # 初始化标志变量
        isIncreasing = True
        isDecreasing = True
        
        # 遍历数组
        for i in range(1, len(nums)):
            if nums[i] > nums[i - 1]:
                isDecreasing = False
            if nums[i] < nums[i - 1]:
                isIncreasing = False
        
        # 返回结果
        return isIncreasing or isDecreasing
        
相关推荐
qq_3729069331 分钟前
mysql用户无法访问存储过程权限提示_MySQL EXECUTE赋权方案
jvm·数据库·python
biubiubiu070632 分钟前
python解释器安装
python
jiang_bluetooth34 分钟前
奈奎斯特第一准则理解和WIFI OFDM的关联
算法
qq_392690662 小时前
如何正确解析含 HTML 实体的 XML 字符串并渲染为 HTML 表格
jvm·数据库·python
qq_414256572 小时前
SQL如何处理时间序列缺失值_利用窗口函数进行前后值填充
jvm·数据库·python
2301_803875613 小时前
CSS如何制作导航栏平滑移动_使用transition与left属性
jvm·数据库·python
DuHz8 小时前
论文精读:大语言模型 (Large Language Models, LLM) —— 一项调查
论文阅读·人工智能·深度学习·算法·机器学习·计算机视觉·语言模型
加农炮手Jinx8 小时前
LeetCode 72. Edit Distance 题解
算法·leetcode·力扣
借雨醉东风8 小时前
程序分享--常见算法/编程面试题:旋转矩阵
c++·线性代数·算法·面试·职场和发展·矩阵
茅盾体8 小时前
汽车零件订单自动同步系统方案
python