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]
相关推荐
渣渣xiong34 分钟前
从零开始:前端转型AI agent直到就业第五十七天-第五十八天
前端·人工智能·python
小L~~~1 小时前
基于贪心策略的混合遗传算法求解01背包问题
python·算法
才兄说2 小时前
机器人二次开发机器人动作定制?动作迁移数据优化
python
洛水水2 小时前
【力扣100题】53.最长回文子串
算法·leetcode·职场和发展
用户8356290780512 小时前
用 Python 实现 Excel 散点图绘制与定制
后端·python
PAK向日葵2 小时前
从零实现 Python 虚拟机(一):PVM 基本原理介绍
python
神所夸赞的夏天2 小时前
创建虚拟环境提示SSLError错误
python
极光代码工作室2 小时前
基于机器学习的二手商品价格预测系统
人工智能·python·深度学习·机器学习
无情的西瓜皮2 小时前
MCP协议实战:从零搭建一个AI Agent工具服务器
运维·服务器·python
过期动态3 小时前
【LeetCode 热题 100】盛最多水的容器
java·数据结构·spring boot·算法·leetcode·spring cloud·职场和发展