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]
相关推荐
郭老二3 小时前
【Python】基本语法:装饰器语法糖@
python
闪电悠米4 小时前
力扣hot100-48.旋转图像-转置翻转详解
算法·leetcode·职场和发展
_Jimmy_4 小时前
Agent常用检索器的详细介绍
python·langchain
小柯南敲键盘4 小时前
图片翻译API接入与自动化实现指南
运维·python·自动化
旅僧5 小时前
Q-learning(自用)
python·机器学习
啦啦啦啦啦zzzz5 小时前
算法:贪心算法
c++·算法·leetcode·贪心算法
Python大数据分析@5 小时前
曝梁文锋称「一度不想维护C端用户,奈何赶不走」,DeepSeek真不需要C端用户吗?可能会有啥影响吗?
python
艾斯特_6 小时前
工作流与多Agent协作:LangGraph、MCP和A2A的应用分层
人工智能·python·ai
IT小盘6 小时前
04-大模型流式输出原理-SSE与Python实现
开发语言·网络·人工智能·python
我叫黑大帅6 小时前
add()和 __add__() 写法哪个更好呢?
后端·python·面试