Leetcode练习
2024-09-03 13:46:36
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 {
res := []int{}
for k1,v1 := range nums {
for k2,v2 := range nums {
if ((v1 + v2) == target) {
res = []int{k1,k2}
break
}
}
}
return res
}
最新文章
- ObjectStream 及 序列化 介绍
- Apkplug 开发常见问题解答
- C语言字符串处理函数
- HDU 5053 the Sum of Cube
- jQuery-事件以及动画
- OpenHCI - 4.2 Endpoint Descriptor
- VK Cup 2012 Qualification Round 1 C. Cd and pwd commands 模拟
- 自定义构造、description方法、SEL
- mysql出现Can't connect to MySQL server on 'localhost' (10061)的解决方法
- inux中shell变量$#,$@,$0,$1,$2的含义
- nvm配置
- JEECG中出现Java.sql.SQLException: Value 'xxxx' can not be represented as java.sql.Timestamp的解决办法
- 信息安全之路-web-xss学习(2)
- np.corrcoef()方法计算数据皮尔逊积矩相关系数(Pearson's r)
- Flume 1.5.0简单部署试用
- UVa 12219 公共表达式消除
- hadoop2.6 上hive运行 报“native-lzo library not available”异常处理
- angularJS1笔记-(20)-模块化加载机制seajs
- 一些常见http状态码
- ShipStation Now Uses AWS And Amazon Fulfillment To Automatically Ship From eBay, Sears And Other Marketplaces