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]
相关推荐
limenga1022 分钟前
TensorFlow Keras:快速搭建神经网络模型
人工智能·python·深度学习·神经网络·机器学习·tensorflow
心软小念33 分钟前
用Python requests库玩转接口自动化测试!测试工程师的实战秘籍
java·开发语言·python
CoderYanger2 小时前
A.每日一题——2536. 子矩阵元素加 1
java·线性代数·算法·leetcode·矩阵
sanggou2 小时前
【Python爬虫】手把手教你从零开始写爬虫,小白也能轻松学会!(附完整源码)
开发语言·爬虫·python
geng_zhaoying2 小时前
在VPython中使用向量计算3D物体移动
python·3d·vpython
半tour费3 小时前
TextCNN-NPU移植与性能优化实战
python·深度学习·分类·cnn·华为云
普通网友3 小时前
使用Flask快速搭建轻量级Web应用
jvm·数据库·python
百锦再3 小时前
第17章 模式与匹配
开发语言·后端·python·rust·django·内存·抽象
普通网友3 小时前
Python函数定义与调用:编写可重用代码的基石
jvm·数据库·python
倦王4 小时前
力扣日刷251117
算法·leetcode·职场和发展