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 小时前
当AI开始“边想边干”:深入聊聊ReAct,以及如何用Python手搓一个简单Agent
python·面试·agent
全栈弄潮儿4 小时前
Python实战第8期:函数
后端·python·编程语言
卷无止境5 小时前
暗流与破局:AI时代的代码安全审查工具全景指南
后端·python
卷无止境8 小时前
一人公司的全栈选型指南:让 AI Agent 写得快,也让生意跑得稳
后端·python
滴啦嘟啦哒9 小时前
【具身笔记】【π0.5 微调与仿真】五、在MuJoCo中实现可视化仿真
笔记·python·vla·具身
全栈练习生10 小时前
AI安全与红队测试
python·ai
费曼学习法10 小时前
把「发送成功」当「送达」?我排查 IM 长消息被静默吞掉的完整过程
python·ai编程·自动化运维
鸽鸽程序猿10 小时前
【项目】【在线判题系统】b端题目增删改
开发语言·python
NetX行者10 小时前
Python 工程化入门:从脚本到规范的 Python 项目结构
网络·python
MasonYyp10 小时前
asyncio并发协程
python