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]
相关推荐
weixin199701080166 分钟前
[特殊字符]《跨境二手ERP对接Back Market:标准化API + 7~10工作日技术合规审核实录》(附Python源码)
开发语言·python·pandas
持敬chijing44 分钟前
Python-数据类型-列表
开发语言·python·青少年编程
2601_962301011 小时前
Python环境搭建及PyCharm破解使用技巧
python·pycharm·环境搭建·避坑技巧·破解使用
Navigator_Z2 小时前
LeetCode //C - 1240. Tiling a Rectangle with the Fewest Squares
c语言·算法·leetcode
稻米哟2 小时前
力扣100——双指针
算法·leetcode
2601_962099463 小时前
Python中的find()函数:用法和示例
python·字符串·索引·子字符串·find函数
大圣编蚕3 小时前
Java StringWriter 详解:从入门到实战
java·开发语言·python
for_ever_love__4 小时前
python基础语法学习: requirements.txt
开发语言·python·学习
程序员清风4 小时前
FastAPI 入门:用 Python 快速开发现代后端服务
python·oracle·fastapi
SunnyDays10114 小时前
使用 Python 提取 Word 文档中的表格数据
python·word