力扣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
        
相关推荐
嫂子的姐夫7 分钟前
050-wx小程序合肥住房
爬虫·python·小程序·逆向
爱吃提升11 分钟前
Python 多线程 threading + 多进程 multiprocessing 完整实操教程
开发语言·python
许彰午16 分钟前
24_Java NIO核心组件
java·python·nio
lie..27 分钟前
基于大模型的智能客服系统部署与使用(二):接入前端可视化界面
人工智能·python
光影62732 分钟前
Python接口自动化测试----Requests库基础入门
开发语言·python·测试工具·pycharm·自动化
程序媛_32 分钟前
【Python】连接PostgreSQL获取手机验证码
开发语言·python·postgresql
Kobebryant-Manba36 分钟前
学习参数管理
pytorch·python·深度学习
是有头发的程序猿37 分钟前
竞品分析 + 用户洞察自动化|基于 item_review 评论接口 + 多 AI Agent 实现淘宝评论全量采集与智能分析(附python源码)
java·python·自动化
信看37 分钟前
Jetson Orin Quectel QMI 拨号上网
开发语言·python
小欣加油40 分钟前
Leetcode31 下一个排列
数据结构·c++·算法·leetcode·职场和发展