【两数之和 II - 输入有序数组】python刷题记录

R3-二分查找

双指针简单题

python 复制代码
class Solution:
    def twoSum(self, numbers: List[int], target: int) -> List[int]:
        #双指针法
        i=0
        j=len(numbers)-1
        while i<j:
            s=numbers[i]+numbers[j]
            if s>target:
                j-=1
            elif s<target:
                i+=1
            else:
                return i+1,j+1
        return []
相关推荐
玩电脑的辣条哥39 分钟前
一台服务器已经有个python3.11版本了,如何手动安装 Python 3.10,两个版本共存
服务器·python·python3.11
weixin_307779131 小时前
PySpark实现ABC_manage_channel逻辑
开发语言·python·spark
莹莹学编程—成长记2 小时前
string的模拟实现
服务器·c++·算法
海天一色y2 小时前
Pycharm(十六)面向对象进阶
ide·python·pycharm
??? Meggie2 小时前
【Python】保持Selenium稳定爬取的方法(防检测策略)
开发语言·python·selenium
XIE3923 小时前
Browser-use使用教程
python
酷爱码4 小时前
如何通过python连接hive,并对里面的表进行增删改查操作
开发语言·hive·python
画个大饼4 小时前
Go语言实战:快速搭建完整的用户认证系统
开发语言·后端·golang
蹦蹦跳跳真可爱5894 小时前
Python----深度学习(基于深度学习Pytroch簇分类,圆环分类,月牙分类)
人工智能·pytorch·python·深度学习·分类
喵先生!5 小时前
C++中的vector和list的区别与适用场景
开发语言·c++