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]
相关推荐
hnxaoli3 分钟前
统信小程序(十六)xls转xlsx
开发语言·python·小程序
梦想三三11 分钟前
Flask + PyTorch模型部署实战:从训练权重到API接口完整工程解析(附完整代码)
人工智能·pytorch·python·flask·模型推理·ai 工程化
杨超越luckly34 分钟前
Agent 应用指南:基于 OurAirports 的中国机场设施数据可视化
python·html·github·可视化·机场设施
卷无止境37 分钟前
pytest 从零到实战:要想代码好,测试少不了
后端·python
吃糖的小孩1 小时前
# RootGraph v1.5 收工:我给 QQ 机器人补上了聊天运行时的“黑匣子”
python
hangyuekejiGEO1 小时前
临沂GEO技术服务方案对比分析
大数据·人工智能·python
人道领域2 小时前
【LeetCode刷题日记】贪心算法理论与实战:455.分发饼干最优解
java·开发语言·数据结构·算法·leetcode·贪心算法
xin_yao_xin2 小时前
Conda 环境的 CUDA PATH 配置指南
开发语言·python·conda·cuda
Zhan8611242 小时前
西班牙股票行情数据API的WebSocket接入:IBEX35指数实时推送与数据清洗
python·websocket·网络协议
he___H2 小时前
基于LCEL的联想
开发语言·python·langchain