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}
}
相关推荐
未知陨落14 小时前
LeetCode:95.编辑距离
算法·leetcode
名誉寒冰16 小时前
【LeetCode】454. 四数相加 II 【分组+哈希表】详解
算法·leetcode·散列表
tao35566717 小时前
【Python刷力扣hot100】49. Group Anagrams
开发语言·python·leetcode
夏鹏今天学习了吗18 小时前
【LeetCode热题100(35/100)】LRU 缓存
算法·leetcode·缓存
Q741_14720 小时前
C++ 位运算 高频面试考点 力扣137. 只出现一次的数字 II 题解 每日一题
c++·算法·leetcode·面试·位运算
墨染点香21 小时前
LeetCode 刷题【103. 二叉树的锯齿形层序遍历、104. 二叉树的最大深度、105. 从前序与中序遍历序列构造二叉树】
算法·leetcode·职场和发展
sitellla1 天前
Testify Go测试工具包入门教程
git·测试工具·其他·golang
Brookty1 天前
【算法】二分查找(一)朴素二分
java·学习·算法·leetcode·二分查找
黑色的山岗在沉睡1 天前
LeetCode 2761. 和等于目标值的质数对
算法·leetcode·职场和发展