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]
相关推荐
lbb 小魔仙7 小时前
Git + Python 项目工作流最佳实践:pre-commit、CI、CHANGELOG 自动化
git·python·ci/cd
dyxal7 小时前
最长公共子序列(LCS)
python·算法
你驴我7 小时前
WhatsApp Cloud API 速率限制下的令牌桶与退避策略实践
网络·后端·python
AC赳赳老秦7 小时前
司法公开数据采集应用:OpenClaw 抓取裁判文书公开信息,批量整理同类参考案例
java·大数据·python·数据挖掘·数据分析·php·openclaw
小大宇8 小时前
Python 集成 Conda
开发语言·python·conda
初学者,亦行者9 小时前
利用Pyecharts绘制堆叠柱状图
python·信息可视化·数据分析
林泽毅9 小时前
PyTRIO:当强化学习不再需要本地GPU
人工智能·python·深度学习·机器学习
小陈phd9 小时前
QAnything 阅读优化策略05——检索
人工智能·python·机器学习
ruofu339 小时前
wsl端是py312,但是项目是py311, 如何下载py311的依赖包(wheels)
python·docker
hold?fish:palm9 小时前
9 找到字符串中所有字母异位词
c++·算法·leetcode