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}
}
相关推荐
j_xxx404_1 小时前
数据结构:栈和队列力扣算法题
c语言·数据结构·算法·leetcode·链表
Lris-KK2 小时前
【Leetcode】高频SQL基础题--180.连续出现的数字
sql·leetcode
珍珠是蚌的眼泪2 小时前
LeetCode_位运算
leetcode·位运算·异或·韩明距离·数字的补数
野犬寒鸦2 小时前
力扣hot100:旋转图像(48)(详细图解以及核心思路剖析)
java·数据结构·后端·算法·leetcode
墨染点香2 小时前
LeetCode 刷题【61. 旋转链表】
算法·leetcode·职场和发展
岁忧2 小时前
(LeetCode 面试经典 150 题) 200. 岛屿数量(深度优先搜索dfs || 广度优先搜索bfs)
java·c++·leetcode·面试·go·深度优先
一枝小雨2 小时前
【OJ】C++ vector类OJ题
数据结构·c++·算法·leetcode·oj题
Tisfy3 小时前
LeetCode 3516.找到最近的人:计算绝对值大小
数学·算法·leetcode·题解
自信的小螺丝钉3 小时前
Leetcode 206. 反转链表 迭代/递归
算法·leetcode·链表
黑色的山岗在沉睡3 小时前
LeetCode 189. 轮转数组
java·算法·leetcode