力扣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
        
相关推荐
Niuguangshuo5 小时前
论文解读:CTC,端到端序列识别的开山之作
算法·语音识别
讳疾忌医丶5 小时前
深度拆解 RocksDB 内核:基于 C++17 的 FIFO 调度状态机与温度阶梯自愈设计
java·c++·算法·架构
花酒锄作田5 小时前
FastAPI 使用 session 认证
python·fastapi
lsswear5 小时前
Python 并发 线程
开发语言·python
高亦真5 小时前
今天是学习嵌入式的第37天
linux·学习·算法
Ivanqhz6 小时前
MLIR OpBuilder
开发语言·python·mlir
罗西的思考7 小时前
[Agent Memory / 强化学习] MemPO源码学习笔记 --- (2)--- 训练
人工智能·算法·机器学习
威联通安全存储7 小时前
TS-h2287XU-RP 在家电制造总装与质检数据场景的部署
python·制造
泡泡鱼(敲代码中)8 小时前
Python 字符串 str 完整学习笔记
python·学习
深圳市方中禾科技8 小时前
FZH1625 LCD 驱动芯片深度评测与实战指南
算法·led