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]
相关推荐
惊讶的猫12 分钟前
langchian_agent的高级使用
python
fbincon1 小时前
Claude Code 自定义状态栏工具:安装、配置与 Subagent 状态展示
python·typescript·claude·claude-code·statusline
yunfengzhineng1 小时前
天津立体库货架配套厂家
大数据·运维·人工智能·python
Nil2082 小时前
leetcode 5最长回文子串
算法·leetcode·职场和发展
m0_674571972 小时前
力扣 hot 100 python
python·算法·leetcode
小白快快跑哦2 小时前
python-字符串全解(六):正则表达式-元字符与转义
python·正则表达式·字符串·元字符·转义
Want5952 小时前
Python炫酷烟花①
开发语言·python
青少儿编程课堂2 小时前
蓝桥杯+全国青少年信息素养大赛+电子学会PythonC/C++考级:最长公共子序列LCS解析
c++·python·算法·bfs·信息学竞赛
Y3815326623 小时前
印度电商数据采集教程:用 SerpBase 查 Flipkart/Myntra/Ajio 商品(附代码)
数据库·python
阿维的博客日记3 小时前
大白话解析快排Python
python