力扣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
        
相关推荐
暴风鱼划水4 分钟前
大型语言模型(入门篇)C
python·语言模型·大模型·llm
l1t4 分钟前
对clickhouse给出的二分法求解Advent of Code 2025第10题 电子工厂 第二部分的算法理解
数据库·算法·clickhouse
Tisfy5 分钟前
LeetCode 3315.构造最小位运算数组 II:位运算
算法·leetcode·题解·位运算
人工智能AI技术6 分钟前
【Agent从入门到实践】20 LLM的基础使用:API调用(OpenAI、国产大模型),程序员快速上手
人工智能·python
云上凯歌8 分钟前
01_AI工具平台项目概述.md
人工智能·python·uni-app
R-sz8 分钟前
app登录接口实现,基于JWT的APP登录认证系统实现方案
java·开发语言·python
WangYaolove131412 分钟前
基于图像取证技术研究与实现(源码+文档)
python·django·毕业设计·源码·计算机源码
程序员敲代码吗16 分钟前
用Python监控系统日志并发送警报
jvm·数据库·python
qwerasda12385218 分钟前
YOLO13-SEG-RFAConv:隧道围岩病理缺陷识别的改进方法与底层逻辑
python
YuTaoShao19 分钟前
【LeetCode 每日一题】1292. 元素和小于等于阈值的正方形的最大边长
算法·leetcode·职场和发展