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]
相关推荐
江华森3 分钟前
Python 实现 2048 游戏(三):面向对象重构与AI模拟
python
可以飞的话37 分钟前
五、数据处理1
python
鱼毓屿御39 分钟前
Python 装饰器与函数调用机制(复习笔记 · 2026-07-07)
开发语言·python
AC赳赳老秦1 小时前
采购专员自动化:OpenClaw 自动比价、生成询价单、跟踪供应商报价进度实战指南
开发语言·数据库·人工智能·python·自动化·github·openclaw
ednO8nqdR1 小时前
Python小游戏制作:如何实现可配置的跨分辨率界面布局
python·plotly·django·virtualenv·scikit-learn·fastapi·pygame
tachibana21 小时前
hot100 排序链表(148)
java·数据结构·算法·leetcode·链表
林泽毅1 小时前
Qwen3.5 DPO 模型对齐实战(pytrio训练版)
人工智能·python·算法
荣码1 小时前
LangGraph多步工作流:Agent不够用的时候,我踩了4个坑
java·python
曲幽2 小时前
从卡顿到丝滑:FastAPI 调用外部 API 的正确姿势(httpx 实战)
python·fastapi·web·async·httpx·client·await·requests·aiohttp
不能跑的代码不是好代码2 小时前
二叉树从基础概念到LeetCode实战
算法·leetcode