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]
相关推荐
许彰午1 小时前
100_Python面试常见问题汇总
java·python·面试
皓悦编程记1 小时前
【YOLO26 系列】基于YOLO26的垃圾分类检测系统【python源码+Pyqt5界面/WEB+数据集+训练代码】
python·qt·分类
滴滴滴嘟嘟嘟.1 小时前
强化学习消融实验-batch_size / clip_range / gae_lambda / lr
python·机器学习
2601_963932981 小时前
怀孕四个月能做流产吗?中期妊娠终止方式与子宫修护科普指南
python
zhr_math_king1 小时前
LangGraph-快速入门-第一个例子
python·langchain
爱吃苹果的梨叔2 小时前
2026年指挥中心分布式坐席怎么选?清虹创智让多系统、多坐席和大屏真正协同
python
起予者汝也3 小时前
Python 数据结构
开发语言·数据结构·python
LadenKiller3 小时前
2026年量化工具增量,放回回测模拟实盘阶段判断
人工智能·python
石一峰6993 小时前
驱动:私有数据为什么要在三个地方各挂一遍?
数据库·python·算法
2601_956319883 小时前
最新量化软件怎么选,先按能力短板匹配工具类型
人工智能·python