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]
相关推荐
CodeSheep程序羊4 分钟前
宇树科技,即将上市!
java·c语言·c++·人工智能·python·科技·硬件工程
AI玫瑰助手5 分钟前
Python函数:内置函数(len/max/min/sorted等)详解
android·开发语言·python
ziyitty9 分钟前
解决Windows下Bash调用Python输出中文乱码的问题
windows·python·bash
栈溢出了10 分钟前
torch.gather 用法笔记
pytorch·python·深度学习
杨超越luckly16 分钟前
Agent应用指南:利用GET请求获取赛力斯汽车门店位置信息
python·html·汽车·可视化·门店
花月C19 分钟前
Agent上下文三级压缩
python·prompt·ai编程
开源Z24 分钟前
LeetCode 238 · 除自身以外数组的乘积:左右两遍扫描,不用除法
算法·leetcode
专注搞钱26 分钟前
用Python写了个SPC自动分析工具,效率提升10倍
开发语言·python
yijianace33 分钟前
Python爬虫实战:ThreadPoolExecutor多线程采集书籍信息与图片下载
开发语言·爬虫·python
郝亚军40 分钟前
win11安装python3.12.7和pycharm
ide·python·pycharm