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]
相关推荐
吃着火锅x唱着歌4 小时前
LeetCode 3885.设计事件管理器
算法·leetcode·职场和发展
土司大王5 小时前
LeetCode hto100——字母异位词分组
java·算法·leetcode
中科高级技工学校5 小时前
乌鲁木齐美术艺考技校实践分享
人工智能·python
CodeBlog-star6 小时前
LLM能力与边界:多模态、幻觉、上下文窗口及开源模型对比
人工智能·python·开源·llm
COOLMO研究AI6 小时前
Python 如何实现 AI API 的动态路由与多通道负载均衡:多账号与多供应商的高可用调度
人工智能·python·负载均衡
土司大王6 小时前
LeetCode hot100——两数之和
数据结构·算法·leetcode
菜冻鱼6 小时前
Python-sklearn-降维
开发语言·人工智能·python·机器学习·支持向量机·sklearn
OptimizationMaster6 小时前
Python自动重启中国移动光猫(ZXHN G7611V2)
python·自动化工具·重启中国移动光猫
Navigator_Z6 小时前
LeetCode //C - 1200. Minimum Absolute Difference
c语言·算法·leetcode
wabs6667 小时前
关于字符串【力扣344.反转字符串的思考】
数据结构·算法·leetcode