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

题目:

题解:

Go 复制代码
func twoSum(numbers []int, target int) []int {
    low, high := 0, len(numbers) - 1
    for low < high {
        sum := numbers[low] + numbers[high]
        if sum == target {
            return []int{low + 1, high + 1}
        } else if sum < target {
            low++
        } else {
            high--
        }
    }
    return []int{-1, -1}
}
相关推荐
阿Y加油吧9 分钟前
LeetCode 双指针经典双题解|盛最多水的容器 + 三数之和,从入门到进阶吃透套路
算法·leetcode·职场和发展
AlenTech13 小时前
141. 环形链表 - 力扣(LeetCode)
数据结构·leetcode·链表
dulu~dulu14 小时前
算法---寻找和为K的子数组
笔记·python·算法·leetcode
佑白雪乐14 小时前
<ACM进度212题>[2026-3-1,2026-3-26]
算法·leetcode
穿条秋裤到处跑14 小时前
每日一道leetcode(2026.03.26):等和矩阵分割 II
算法·leetcode·矩阵
x_xbx15 小时前
LeetCode:1. 两数之和
数据结构·算法·leetcode
x_xbx15 小时前
LeetCode:49. 字母异位词分组
算法·leetcode·职场和发展
老鼠只爱大米17 小时前
LeetCode经典算法面试题 #55:跳跃游戏(贪心法、动态规划、BFS等多种实现方案详解)
算法·leetcode·贪心算法·动态规划·bfs·java面试·跳跃游戏
旖-旎18 小时前
前缀和(矩阵区域和)(8)
c++·算法·leetcode·前缀和·动态规划
liuyao_xianhui19 小时前
优选算法_翻转链表_头插法_C++
开发语言·数据结构·c++·算法·leetcode·链表·动态规划