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]
相关推荐
Hi李耶6 小时前
【LeetCode】15.三数之和
java·算法·leetcode
DogDaoDao6 小时前
【第10篇】Python 异常处理与调试入门
python·深度学习·ai·程序员·大模型·异常处理与调试
程序员雷欧6 小时前
Java 反射深度解析:从原理到源码的全面剖析
java·开发语言·python
rannn_1116 小时前
【力扣hot100】链表专题|21、2、19、24、92、25
java·数据结构·算法·leetcode·链表·开发
我的xiaodoujiao7 小时前
快速学习Python基础知识详细图文教程18--多线程
开发语言·python·学习·测试工具
鹿角片ljp7 小时前
LeetCode 21. 合并两个有序链表
算法·leetcode·链表
Rabitebla7 小时前
C++11 新特性详解(一):列表初始化、initializer_list 与右值引用
java·开发语言·数据结构·c++·算法·leetcode·list
❀搜不到7 小时前
isat-sam分割导出掩码图
开发语言·python
Zane19948 小时前
ClassName() 只是一步?拆开看 __new__ 和 __init__ 各自在干什么
后端·python
曾阿伦8 小时前
Trae CN Python环境调试debug指南
开发语言·python