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]
相关推荐
dust_and_stars2 小时前
Streamlit vs Gradio 完整对比
服务器·python
winfredzhang2 小时前
Python + wxPython + SQLite 实战:开发一个本地 Python 项目一键启动管理工具
python·sqlite·bat·截图·claudecode·codingliteplan
星越华夏2 小时前
python中四种获取文件后缀名的方法
开发语言·python
lunzi_08262 小时前
【学习笔记】《Python编程 从入门到实践》第9章:类、继承、组合与面向对象编程
笔记·python·学习
大蚂蚁2号2 小时前
本地批量音视频转文本免费工具
python·音视频·开源软件
copyer_xyf2 小时前
FastAPI 项目骨架搭建
前端·后端·python
十正2 小时前
aiohttp.TCPConnector 连接池原理详解
网络·python·tcp·aiohttp
洛水水2 小时前
【力扣100题】89.下一个排列
数据结构·算法·leetcode
洛水水2 小时前
【力扣100题】90.寻找重复数
算法·leetcode·职场和发展
LoserChaser2 小时前
Flask 文件上传服务器 - 知识点总结
服务器·python·flask