leetcode第321题-LeetcodeInGo:Leetcode在Go

时间:2021-07-06 22:48:28
【文件属性】:
文件名称:leetcode第321题-LeetcodeInGo:Leetcode在Go
文件大小:9KB
文件格式:ZIP
更新时间:2021-07-06 22:48:28
系统开源 leetcode第321题 LeetcodeInGo Leetcode In Go 1. 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。 示例: 给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums[1] = 2 + 7 = 9 所以返回 [0, 1] 解题: func twoSum(nums []int, target int) []int { var tmp = map[int]int{} for i := range nums{ if s,ok := tmp[target-nums[i]];ok { return []int{s,i} } tmp[nums[i]] = i } return nil } 2. 两数相加 给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。 如果,我
【文件预览】:
LeetcodeInGo-master
----LICENSE(11KB)
----README.md(10KB)

网友评论