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]
相关推荐
gpfyyds66625 分钟前
Python代码练习
开发语言·python
YuTaoShao37 分钟前
【LeetCode 每日一题】1653. 使字符串平衡的最少删除次数——(解法三)DP 空间优化
算法·leetcode·职场和发展
cpp_25011 小时前
P10570 [JRKSJ R8] 网球
数据结构·c++·算法·题解
cpp_25011 小时前
P8377 [PFOI Round1] 暴龙的火锅
数据结构·c++·算法·题解·洛谷
TracyCoder1231 小时前
LeetCode Hot100(26/100)——24. 两两交换链表中的节点
leetcode·链表
aiguangyuan2 小时前
使用LSTM进行情感分类:原理与实现剖析
人工智能·python·nlp
小小张说故事2 小时前
BeautifulSoup:Python网页解析的优雅利器
后端·爬虫·python
luoluoal2 小时前
基于python的医疗领域用户问答的意图识别算法研究(源码+文档)
python
cpp_25012 小时前
P9586 「MXOI Round 2」游戏
数据结构·c++·算法·题解·洛谷
Shi_haoliu2 小时前
python安装操作流程-FastAPI + PostgreSQL简单流程
python·postgresql·fastapi