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]
相关推荐
Chasing__Dreams5 分钟前
python--杂识--18.1--pandas数据插入sqlite并进行查询
python·sqlite·pandas
黑听人14 分钟前
【力扣 困难 C】115. 不同的子序列
c语言·leetcode
彭泽布衣1 小时前
python2.7/lib-dynload/_ssl.so: undefined symbol: sk_pop_free
python·sk_pop_free
喜欢吃豆1 小时前
从零构建MCP服务器:FastMCP实战指南
运维·服务器·人工智能·python·大模型·mcp
一个处女座的测试2 小时前
Python语言+pytest框架+allure报告+log日志+yaml文件+mysql断言实现接口自动化框架
python·mysql·pytest
nananaij2 小时前
【Python基础入门 re模块实现正则表达式操作】
开发语言·python·正则表达式
蛋仔聊测试2 小时前
Playwright 网络流量监控与修改指南
python
前端拿破轮3 小时前
🤡🤡🤡面试官:就你这还每天刷leetcode?连四数相加和四数之和都分不清!
算法·leetcode·面试
nightunderblackcat3 小时前
进阶向:Python音频录制与分析系统详解,从原理到实践
开发语言·python·音视频
慕婉03073 小时前
Tensor自动微分
人工智能·pytorch·python