1_twoSum
来源:互联网 发布:常用 windows api 编辑:程序博客网 时间:2024/05/19 20:42
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
给定一个整形数组和一个目标值,返回数组中的两个下标,这两个下标的值之和等于目标值You may assume that each input would have exactly one solution, and you may not use the same element twice.
你可以假设每个输入的数组只有一个解,并且你不能重复使用同一个元素
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ length = len(nums) for i in range(length): for j in range(i,length): need = target - nums[i] if i != j and nums[j] == need: return (i,j)
阅读全文
0 0
- 1_TwoSum
- 1_twoSum
- LeetCode:1_TwoSum--C++实现
- 1
- 1
- 1
- 1
- 1
- 1
- 1》
- 1
- 1
- 1
- 1
- (1)
- 1
- 1
- 1
- pandas处理大数据的一些小技巧
- position absolute relative的区别
- 启动Apache时出现:(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 : AH00072: make_sock: could not bind to address
- LeetCode | 65. Valid Number
- HTML5 新特性大全
- 1_twoSum
- mysql中文乱码的解决方法
- easyui怎么将前台表单数据传递给后台?
- 给一个整数数组,输出所有可能的子集
- 买房时补充协议写哪些?合同七大条款要注意!
- 【Linux】红帽7搭建网络YUM源
- 1.18Android 学习+进度之十八-IP框添加,并测试
- 端口占用 tomcat 8080
- UNP(卷2:进程间通信)—— 第6章:System V消息队列