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]
相关推荐
外收内放2 分钟前
Python基础语法练习题(62原始版本及其优化版本)
开发语言·python
棉猴4 分钟前
玩游戏学Python4-字符串
python·游戏·字符串·pygame·玩游戏
东来也_八门32 分钟前
我用麦当劳开放的 MCP,把那个最冷门的营养接口做成了真实配餐求解器
python
AI日报派送佬39 分钟前
Ultralytics YOLO 模型训练技巧与最佳实践
人工智能·python·深度学习·yolo·机器学习·计算机视觉
zhaowangji1 小时前
mujoco仿真(机械臂推动正方体到指定位置)
人工智能·python
数据管道工1 小时前
解析一个老网站:GBK 编码、页面结构漂移与限流退避
python
只睡四小时1 小时前
AI 生成 PPTX:11 页课件编译出 429 个形状
javascript·python·pptx·ai生成ppt·ooxml
leisoo80971 小时前
股票筹码分布怎么用获利比例成本区间与集中度实战 IG50免费开源股票数据API接口
开发语言·jvm·数据库·python·开源
ControlM1 小时前
从官方 CDN 里扒出 TRAE (TraeCode) 历史版本安装包
python·逆向·trae
tianyuanwo1 小时前
Python 属性查找陷阱:从 `AttributeError: ‘X‘ object has no attribute ‘_children‘` 说起
python