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]
相关推荐
江华森几秒前
03-python-包与模块异常处理
python
AI行业学习7 分钟前
2026 版 Notepad++ 完整图文安装指南|官方渠道无捆绑,一键切换中文界面
开发语言·人工智能·python·html·notepad++
炘东59214 分钟前
求助:在另一个 Reasonix 窗口或后台运行
python
apcipot_rain18 分钟前
计科八股2026705——正态分布、独立与不相关、范数、列表元组集合、链表队列、sort函数、URL执行
python·计算机网络·概率论
江华森26 分钟前
Python 编程快速上手:让繁琐工作自动化 —— 19章全实战笔记
笔记·python·自动化
子豪-中国机器人31 分钟前
第一部分:初赛选择题(30 题,对应线上每日问答)
python
Sam092732 分钟前
【AI 算法精讲 15】余弦相似度:向量检索与归一化内积
人工智能·python·算法·ai
Starry-sky(jing)1 小时前
RecursionError: maximum recursion depth exceeded —— 你的函数调用链,踩穿了 CPython 的安全气囊
python·cpython·pydantic·recursionerror·递归深度·递归限制·sys.setrecursionlimit
cui_ruicheng1 小时前
Python从入门到实战(三):流程控制与循环语句
开发语言·python
Rauser Mack1 小时前
Vibe coding游戏实战:零代码编程五子棋小游戏
人工智能·python·游戏·html·prompt