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}
}
相关推荐
Swift社区7 小时前
LeetCode 429 - N 叉树的层序遍历
算法·leetcode·职场和发展
无敌最俊朗@17 小时前
力扣hot100-206反转链表
算法·leetcode·链表
Kuo-Teng18 小时前
LeetCode 279: Perfect Squares
java·数据结构·算法·leetcode·职场和发展
Tony Bai18 小时前
Go 在 Web3 的统治力:2025 年架构与生态综述
开发语言·后端·架构·golang·web3
CoderYanger18 小时前
B.双指针——3194. 最小元素和最大元素的最小平均值
java·开发语言·数据结构·算法·leetcode·职场和发展·1024程序员节
q***062920 小时前
搭建Golang gRPC环境:protoc、protoc-gen-go 和 protoc-gen-go-grpc 工具安装教程
开发语言·后端·golang
前进的李工21 小时前
LeetCode hot100:094 二叉树的中序遍历:从递归到迭代的完整指南
python·算法·leetcode·链表·二叉树
吃着火锅x唱着歌1 天前
LeetCode 面试题 16.24.数对和
算法·leetcode·职场和发展
Dream it possible!1 天前
LeetCode 面试经典 150_二叉树层次遍历_二叉树的层平均值(82_637_C++_简单)
c++·leetcode·面试·二叉树
Wenhao.1 天前
LeetCode Hot100 每日温度
数据结构·算法·leetcode·golang