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]
相关推荐
飞翔的佩奇3 小时前
【完整源码+数据集+部署教程】表盘指针检测系统源码和数据集:改进yolo11-CA-HSFPN
python·yolo·计算机视觉·数据集·yolo11·表盘指针检测
larance4 小时前
SQLAlchemy 的异步操作来批量保存对象列表
数据库·python
搏博4 小时前
基于Python3.10.6与jieba库的中文分词模型接口在Windows Server 2022上的实现与部署教程
windows·python·自然语言处理·flask·中文分词
lxmyzzs5 小时前
pyqt5无法显示opencv绘制文本和掩码信息
python·qt·opencv
萧鼎6 小时前
Python pyzmq 库详解:从入门到高性能分布式通信
开发语言·分布式·python
yujkss7 小时前
Python脚本每天爬取微博热搜-终版
开发语言·python
yzx9910137 小时前
小程序开发APP
开发语言·人工智能·python·yolo
飞翔的佩奇8 小时前
【完整源码+数据集+部署教程】二维码与查找模式检测系统源码和数据集:改进yolo11-CSwinTransformer
python·yolo·计算机视觉·数据集·yolo11·二维码与查找模式检测
圣保罗的大教堂8 小时前
leetcode 2348. 全 0 子数组的数目 中等
leetcode
大霞上仙8 小时前
实现自学习系统,输入excel文件,能学习后进行相应回答
python·学习·excel