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]
相关推荐
quantdash_cc4 分钟前
批量请求和循环请求有什么区别?从 API 请求次数看量化数据获取的工程设计
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
Tizzy JJ21 分钟前
Python + pytest 接口自动化测试框架实战:从零搭建企业级项目骨架
开发语言·python·pytest
海兰22 分钟前
【 Python 量化交易】第8章:量化工具箱
开发语言·python
TheBestRucy27 分钟前
Python九阳神功之柒:数据分析三剑客·执剑问道
开发语言·python·数据分析
鹿角片ljp30 分钟前
LeetCode 56:合并区间复盘|从排序思维到 List<int[]> 的简洁写法
算法·leetcode·list
TheBestRucy41 分钟前
Python九阳神功之陆:数据库持久化与缓存·乾坤大挪移
数据库·python·缓存
坐吃山猪1 小时前
IDEA调试中Evaluate常用操作
java·python·intellij-idea
Tizzy JJ1 小时前
接口自动化测试实战:如何围绕真实业务场景设计高质量用例
python·自动化·pytest
海兰1 小时前
【 Python 量化交易】第10章:八大经典策略
android·python·kotlin