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]
相关推荐
一马平川的大草原16 分钟前
如何实现SVG转Mermaid图
python·svg·格式转换·mermaid
PFFstronger23 分钟前
基于 Dify 知识库 + Ollama 大模型,自动生成测试用例并导出 XMind 的完整方案
人工智能·python·测试用例·xmind
SomeBottle40 分钟前
【小记】图片托管从又拍云迁移到腾讯云 EO + COS(兼容图片处理参数)
python·计算机网络·学习笔记·对象存储·cdn·折腾
cts6181 小时前
FDE架构师前端选型指南
python
2601_962293792 小时前
【Python教程:自动化处理文件】
python·自动化·编程·文件处理·os模块
禹凕2 小时前
快速幂算法详解与实战
python·算法
sylviiiiiia2 小时前
leetcode hot 100
python·算法·leetcode
半摆烂日常2 小时前
自建WMS和买成品:三年成本对比
大数据·服务器·数据库·python·深度学习·低代码·numpy
2601_962296513 小时前
Python的哈希hashlib模块详细解读
python·md5·sha·加密算法·hashlib
chinesegf3 小时前
comfyui便携版的基础使用
python