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 小时前
CANN 调试工具与性能剖析:从日志分析到 NPU 行为追踪的完整调试体系
开发语言·windows·python·深度学习·缓存
隔壁大炮6 小时前
MNE-Python 第9天学习笔记:源定位基础
python·eeg·mne·脑电数据处理
Daydream.V7 小时前
Python Flask超全入门实战教程|从零基础到项目部署
大数据·python·flask
浅念-7 小时前
LeetCode 回溯算法题——综合练习
数据结构·c++·算法·leetcode·职场和发展·深度优先·dfs
databook7 小时前
Manim物理模拟:别自己写欧拉了!
python·数学·动效
圣保罗的大教堂8 小时前
leetcode 61. 旋转链表 中等
leetcode
香蕉鼠片8 小时前
Python进阶学习
开发语言·python
亚亚的学习和分享9 小时前
python练习:人生模拟器(简易版)
python
全糖可乐气泡水9 小时前
Codex适配国产信创环境安装部署与技术适配全解析
开发语言·git·python·算法·百度
LeocenaY9 小时前
搜集的一些测开面试题
开发语言·python