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]
相关推荐
Ulyanov29 分钟前
刚体动力学方程——牛顿-欧拉与陀螺效应的奥秘
开发语言·python·目标跟踪·雷达电子对抗·导引头
观察员35 分钟前
用 Streamlit + 智谱 AI 打造虚拟伴侣聊天机器人
python
Cubar1 小时前
[一]开源ERP:odoo19二次开发问题-原库存模块问题
python·开源·odoo·开源erp
滴滴滴嘟嘟嘟.1 小时前
强化学习-PPO 奖励塑形实验:Pendulum-v1 中角速度惩罚权重的影响
开发语言·python
Sylvia33.2 小时前
足球数据接口开发实战:如何用火星数据API盘活赛事应用
java·服务器·开发语言·数据库·python
lupai2 小时前
身份证二要素实名认证 API 落地应用指南
python
cxr8282 小时前
大语言模型上下文缓存命中率测试全场景清单
人工智能·python·算法·缓存·语言模型·自然语言处理·llm
某林2122 小时前
大模型边缘部署到底层硬件闭环
python·架构·机器人·硬件架构·ros2
LadenKiller3 小时前
最新量化软件选择,先按能力判断表达生成和执行
人工智能·python
退休倒计时3 小时前
【每日一题】LeetCode 287. 寻找重复数 TypeScript
算法·leetcode·typescript