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 分钟前
leetcode 48
算法·leetcode·职场和发展
6Hzlia8 分钟前
【Hot 100 刷题计划】 LeetCode 169. 多数元素 | C++ 哈希表基础解法
c++·leetcode·散列表
唐叔在学习9 分钟前
Python移动端应用消息提醒开发实践
开发语言·python
好家伙VCC10 分钟前
**发散创新:基于Python与OpenCV的视频流帧级分析实战**在当前人工智能与计算机视觉飞速发展的背景下
java·人工智能·python·计算机视觉
米粒110 分钟前
力扣算法刷题 Day 38 (打家劫舍专题)
算法·leetcode·职场和发展
xiaotao13110 分钟前
阶段零:IDE选择 与 Jupyter Notebook / Lab 使用
ide·人工智能·python·jupyter
Pocker_Spades_A17 分钟前
Python快速入门专业版(五十七)——POST请求与模拟登录:从表单分析到实战(以测试网站为例)
开发语言·python
Highcharts.js20 分钟前
企业级数据可视化|BI 仪表板数据中台工业监控平台的选择分析
人工智能·python·信息可视化·数据挖掘·数据分析·highcharts
橙露25 分钟前
Seaborn 高级可视化:统计图表制作与报告导出
python
2601_9544345526 分钟前
2026年专业深度测评:入门电钢琴品牌排名前五权威发布
大数据·人工智能·python