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]
相关推荐
玖玥拾5 分钟前
LeetCode 1 两数之和
算法·leetcode·职场和发展
开源量化GO9 分钟前
学量化:看到“2026年 AI 写 Python”内容时,先用示例和练习补交易认知
人工智能·python
旖旎夜光14 分钟前
LeetCode 974:和可被 K 整除的子数组(前缀和) —— 题解
数据结构·c++·算法·leetcode·前缀和
SelectDB技术团队27 分钟前
StarRocks 适合做日志分析吗?
大数据·数据结构·后端·python·doris·日志分析·starrock
weixin_307779131 小时前
Databricks里用PySpark统计指定表和字段中各字段的空值、空字符串或零值比例
运维·数据仓库·python·spark·云计算
海兰1 小时前
【 Python 量化交易】第6章:数据可视化
开发语言·python·信息可视化
多多鼠1 小时前
Tool Calling的信任边界:从协议校验到执行沙箱的完整链路设计
运维·开发语言·网络·人工智能·python·langchain
Jazz_z1 小时前
使用 Python 合并与取消合并 Excel 单元格
开发语言·python·excel
Lenyiin1 小时前
第6篇_Python高级语法与标准库精髓:从会用到达精通
java·python·html