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]
相关推荐
毕设源码-邱学长25 分钟前
【开题答辩全过程】以 基于Python的Bilibili平台数据分析与可视化实现为例,包含答辩的问题和答案
开发语言·python·数据分析
咚咚王者36 分钟前
人工智能之编程进阶 Python高级:第十一章 过渡项目
开发语言·人工智能·python
A尘埃1 小时前
大模型应用python+Java后端+Vue前端的整合
java·前端·python
A尘埃1 小时前
LLM大模型评估攻略
开发语言·python
一晌小贪欢2 小时前
【Python办公】处理 CSV和Excel 文件操作指南
开发语言·python·excel·excel操作·python办公·csv操作
Kuo-Teng3 小时前
LeetCode 206: Reverse Linked List
java·算法·leetcode·职场和发展
檀越剑指大厂3 小时前
【Python系列】fastapi和flask中的阻塞问题
python·flask·fastapi
YoungHong19924 小时前
【Python进阶】告别繁琐Debug!Loguru一键输出异常日志与变量值
python·debug·异常处理·日志·loguru·log·logger
AiXed4 小时前
PC微信协议之nid算法
python·网络协议·算法·微信