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]
相关推荐
2601_9622186128 分钟前
万象生鲜系统称重自动多退少补算法解决生鲜非标品痛点
大数据·数据库·人工智能·python·算法
Jasmin Tin Wei36 分钟前
ai辅助逆向
python
醇氧1 小时前
Python`__pycache__` 被 Git 跟踪的排查与解决
python·django
XUEYUAN52121 小时前
ASN 自治系统号风控:平台如何通过 IP 所属自治域批量识别代理流量
python·网络协议·http·网络安全·socks5
Zenova EdgeOS2 小时前
Linux ss 工业边缘网络分析实战
linux·python·边缘计算·工业网关
CoderYanger2 小时前
A.每日一题:835. 图像重叠
java·开发语言·程序人生·leetcode·面试·职场和发展·学习方法
成为深度学习高手2 小时前
CrossLinear:即插即用的跨相关嵌入,让线性模型也能用好外生变量
人工智能·python·深度学习·数据挖掘
圣保罗的大教堂2 小时前
leetcode 3524. 求出数组的 X 值 I 中等
leetcode
陈年老古董3 小时前
MediaPipe 姿态检测与脸部关键点检测
笔记·python·opencv·学习·dlib