Python | Leetcode Python题解之第167题两数之和II-输入有序数组

题目:

题解:

python 复制代码
class Solution:
    def twoSum(self, numbers: List[int], target: int) -> List[int]:
        low, high = 0, len(numbers) - 1
        while low < high:
            total = numbers[low] + numbers[high]
            if total == target:
                return [low + 1, high + 1]
            elif total < target:
                low += 1
            else:
                high -= 1

        return [-1, -1]
相关推荐
Nil20810 分钟前
leetcode 72编辑距离
算法·leetcode·职场和发展
尼给路达哟31 分钟前
node(koa)和python(fastapi)面试
python·面试·fastapi
Nil2081 小时前
leetcode 136只出现一次的数字
leetcode·哈希算法·散列表
曲径海盗2 小时前
【Python 学习第 32 天】字符串基础
python·学习笔记·编程入门
lvwangshu2 小时前
川剧复演 题解
动态规划·题解·技巧·性质题·思维好题
田里的水稻2 小时前
PyTorch_torchvision---数据集下载\TensorBoard可视化
人工智能·pytorch·python·深度学习·机器学习
程序员正茂2 小时前
Win11使用自定义训练集训练ncnn模型
python·yolo·图像识别·移动端·ncnn
zwd20052 小时前
Manim 画布尺寸与像素换算详解:frame_width、frame_height、pixel_width 和画质参数(0.21.0 实测)
python·分辨率·manim·数学动画·frame_width·manim教程
最强小杰2 小时前
Claude Opus 4.8 调用报 529 怎么办?并发限制触发过载——退避策略与降级方案完整指南
运维·网络·python·ai
databook3 小时前
MinMax vs Standard vs Robust:三种特征缩放怎么选
python·机器学习·数据分析