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]
相关推荐
麻雀飞吧9 小时前
先判断工具用来学习、开发还是执行
人工智能·python
人邮异步社区10 小时前
学习Python的最佳学习路径是什么?
python·程序员
Navigator_Z12 小时前
LeetCode //C - 1252. Cells with Odd Values in a Matrix
c语言·算法·leetcode
troy12812 小时前
Python 基础语法(九):Django/Flask/FastAPI 三大 Web 框架详细对比解析
python·jupyter·django·flask·github·fastapi
jzshmyt12 小时前
我用 Python 从零“生成“了一个宇宙,然后让它观察自己(v14)
人工智能·pytorch·python·numpy·matplotlib·空间计算·scipy
语戚13 小时前
力扣 1621. 大小为K的不重叠线段的数目:动态规划(Java 实现)
java·算法·leetcode·动态规划·力扣·dp
青山木14 小时前
Hot 100 --- 最长有效括号
java·数据结构·算法·leetcode·动态规划
用户83562907805114 小时前
使用 Python 将 DOCX 转换为 Markdown
后端·python
小玮看世界14 小时前
[Python]ADAS工程实战(三):多传感器扇区统计疑难点全解——归一化、跨边界、去重与置信度
python
这料鬼有毒15 小时前
二刷hot100-1143.最长公共子序列
算法·leetcode·动态规划