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]
相关推荐
一tiao咸鱼6 分钟前
前端转 agent # 02 - FastAPI 框架入门与原理
前端·python
Yolo566Q27 分钟前
Noah-MP陆面过程模型建模方法与站点、区域模拟实践技术应用
开发语言·python
肖永威1 小时前
麒麟 V10 编译 Python 3.11 依赖包缺失与版本冲突问题解决实录
运维·python·麒麟操作系统
Csvn1 小时前
Python 开发技巧 · 类型注解进阶 —— 从 `TypeVar` 到 `Protocol`,让类型检查真正帮你抓 bug
后端·python
W是笔名2 小时前
python___容器类型的数据___列表
开发语言·windows·python
花 满 楼2 小时前
EB引脚配置自动化方案|告别手动繁琐配PIN,Excel+Python批量生成ARXML实现一键配置
python·excel·eb
江华森2 小时前
jieba 分词 + 共现矩阵构建——《釜山行》人物关系提取(二)
python
用户298698530142 小时前
Python 实现 Excel 新旧格式互转:告别 Office 依赖的自动化方案
后端·python·excel
进击切图仔2 小时前
基于千问的白盒蒸馏 SOP
运维·服务器·人工智能·python·效率
2401_868534782 小时前
案例介绍-小型网络规划及搭
python·计算机网络