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]
相关推荐
小白快快跑哦4 分钟前
python-字符串全解(六):正则表达式-修饰符
python·正则表达式·修饰符
niucloud-admin26 分钟前
JAVA V6 多商户商城 开发文档——项目启动
java·开发语言·python
CCIE-Yasuo32 分钟前
个人电脑搭建AI-Qwen3-8B-学习记录
人工智能·python·学习
小猴子爱上树1 小时前
跨马翻译:批量图片翻译+视频字幕+智能抠图,跨境电商翻译工具
python·音视频
棉猴1 小时前
玩游戏学Python2-IDLE与pgzero入门
开发语言·python·游戏·玩游戏·pgzero·pgzrun
INGNIGHT1 小时前
593 · 石头游戏 II (区间dp石子合并 翻倍循环问题)
leetcode
TechEdu2026061 小时前
[人工智能]Python12: SciPy 实战指南
人工智能·python·scipy
aqiu1111112 小时前
【C++算法打怪专栏】LeetCode 402. 移掉 K 位数字(单调栈 + 贪心)
c++·算法·leetcode
jack186892 小时前
Github Copilot 高效开发实战场景指南
python
AIFQuant2 小时前
Python A股实时行情API接入:沪深股票数据与WebSocket推送实战
开发语言·python·websocket·金融·a股行情