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]
相关推荐
阿正的梦工坊4 分钟前
Sliding Window Attention(滑动窗口注意力)解析: Pytorch实现并结合全局注意力(Global Attention )
人工智能·pytorch·python
喜-喜27 分钟前
Python pip 缓存清理:全面方法与操作指南
python·缓存·pip
rgb2gray28 分钟前
GeoHD - 一种用于智慧城市热点探测的Python工具箱
人工智能·python·智慧城市
01_1 小时前
力扣hot100 ——和为k的子数组 前后缀和(积)各种情况总结
数据结构·算法·leetcode·前后缀和(积)计算
MZWeiei1 小时前
Matplotlib,Streamlit,Django大致介绍
python·django·matplotlib
游客5202 小时前
自动化办公|xlwings生成图表
python·自动化
_Itachi__2 小时前
LeetCode 热题 100 206. 反转链表
算法·leetcode·链表
ylfhpy2 小时前
Python常见面试题的详解16
开发语言·python·面试
蹦蹦跳跳真可爱5892 小时前
Python----PyQt开发(PyQt高级:手搓一个音乐播放器)
python·pyqt
高力士等十万人2 小时前
OpenCV对比度增强
人工智能·python·opencv