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]
相关推荐
高洁0131 分钟前
数字孪生与计算机视觉:让机器看懂现场
人工智能·python·机器学习·transformer·迁移学习
ComPDFKit38 分钟前
RAG 回答只显示 PDF 文件名?用 Python 保留引用页码
开发语言·python·pdf·rag
yz_aiks2 小时前
Termux 使用教程:把安卓手机变成随身 Linux(装 Python、SSH 远程、跑自动化脚本)
android·linux·python·智能手机·ssh·termux
2601_967980114 小时前
Flask Web 应用
python·flask·web开发·环境变量·虚拟环境
aifannihao4 小时前
ß 大写变 SS:用 Python 算清 Ruby2Shell 的缓冲区账本
python·安全·标准库·缓冲区溢出·字符串编码
liwulin05065 小时前
【OLLAMA】调用SKILL的通用ReAct
python
郝学胜-神的一滴5 小时前
Effective Python 条款36:优雅拼装迭代器与生成器
开发语言·数据结构·人工智能·python·numpy·scikit-learn
文丑颜不良啊6 小时前
LeetCode3401~3420题目解析
java·leetcode
Norna7 小时前
Git 给路径加了引号,这个文件就从 review 里消失了
python
wuyk5557 小时前
Python办公自动化-第04讲-批量新建Excel
开发语言·python·excel