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]
相关推荐
JarmanYuo35 分钟前
ARM (Attention Refinement Module)
python·计算机视觉
正经教主38 分钟前
【基础】Windows开发设置入门4:Windows、Python、Linux和Node.js包管理器的作用和区别(AI整理)
linux·windows·python·包管理器
Q_Q19632884751 小时前
python的漫画网站管理系统
开发语言·spring boot·python·django·flask·node.js·php
搂……住1 小时前
第一次做逆向
python
卡尔曼的BD SLAMer1 小时前
计算机视觉与深度学习 | Python实现EMD-SSA-VMD-LSTM-Attention时间序列预测(完整源码和数据)
python·深度学习·算法·cnn·lstm
代码的乐趣1 小时前
支持selenium的chrome driver更新到136.0.7103.94
chrome·python·selenium
渴望技术的猿2 小时前
Windows 本地部署MinerU详细教程
java·windows·python·mineru
珊瑚里的鱼2 小时前
【滑动窗口】LeetCode 1658题解 | 将 x 减到 0 的最小操作数
开发语言·c++·笔记·算法·leetcode·stl
Aliano2172 小时前
TestNGException ClassCastException SAXParserFactoryImpl是Java自带的Xerces解析器——解决办法
java·开发语言·python
漫谈网络3 小时前
回调函数应用示例
开发语言·python·回调函数