技术栈

Python | Leetcode Python题解之第167题两数之和II-输入有序数组

Mopes__2024-06-25 5:08

题目:

题解:

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]
上一篇:伸展树(数据结构篇)
下一篇:【Linux】—Apache Hive 安装部署
相关推荐
tsfy2003
24 分钟前
Python批量调整Excel格式,并排版导出PDF
python·pdf·excel
木囧
38 分钟前
PyCharm手动创建虚拟环境
ide·python·pycharm
李可以量化
41 分钟前
QMT 量化实践:两种方式获取个股上市日期(内置 Python + 原生 Python 完整可运行代码)
python
是多巴胺不是尼古丁
1 小时前
期末java复习--string
java·开发语言·python
garmin Chen
1 小时前
从 Transformer 到 Agent:大模型技术全景解析
java·人工智能·python·深度学习·transformer
没有钱的钱仔
1 小时前
pytorch_cuda安装
人工智能·pytorch·python
Full Stack Developme
1 小时前
Apache Tika 教程
java·开发语言·python·apache
Navigator_Z
1 小时前
LeetCode //C - 1096. Brace Expansion II
c语言·算法·leetcode
笨笨没好名字
2 小时前
Leetcode刷题python版第一周
python·算法·leetcode
Cthy_hy
2 小时前
斯特林数:组合划分的递归经典,一二两类全解
python·算法·斯特林数
热门推荐
01HTTP 与 HTTPS 的区别:从原理到实战详解022026 AI 编程工具终极实战指南:Cursor vs Claude Code vs Copilot,开发者该怎么选?032026年6月AI行业全景:从百模大战到Agent元年,这30天发生了什么?04【AI】2026 年具身智能模型和世界模型总结052026 年 AI 编程工具终极横评:Cursor vs Claude Code vs Copilot vs Windsurf06AI科技热点日报 | 2026年6月1日07GitHub 镜像站点08Claude Code、Codex、Cursor三分天下:2026年AI编程Agent生态全景剖析09《置身钉内》原文-可播放阅读10AI一周事件 · 2026-06-03 至 2026-06-09