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]
相关推荐
Shaoshing31 分钟前
LeetCode100 32.最长有效括号
java·数据结构·leetcode
weixin_3077791337 分钟前
Jupyter SQL 表血缘分析并导出 Excel
开发语言·python·sql·算法·excel
benchmark_cc37 分钟前
如何用 Python 计算盈亏痛苦比(Gain-to-Pain Ratio)?
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
sbjdhjd38 分钟前
后端编程语言 PHP 笔记(第 1–3 章)|PHP 简介、版本与运行环境安装
开发语言·人工智能·笔记·后端·python·ai·php
Ivanqhz1 小时前
wb 自动化搬运矩阵: 一条定型 “芯片选型偏好” 的话术?!
人工智能·python·机器学习
小白的高手之路1 小时前
【LeetCode 热题 100】240. 搜索二维矩阵 II|矩阵、二分查找、Z 字形查找(Python)
python·算法·leetcode·矩阵·力扣
geovindu1 小时前
python:DBSCAN
开发语言·后端·python·算法
劲夫学编程1 小时前
leetcode:最长连续序列
leetcode·最长连续序列
斯内普吖1 小时前
(开源)智慧物业管理系统实战指南 基于 Python + Django + uni-app + Vue + MySQL
vue.js·python·django·uni-app·开源
Ponp_8 小时前
用 StyleGAN2 做图像数据扩充实战
python·深度学习·生成对抗网络