LEETCODE 1.Two Sum (python实现)
来源:互联网 发布:索尼z3sim网络解锁 编辑:程序博客网 时间:2024/06/06 00:58
题目:
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.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
翻译:
给定一个整形数组和一个整数target,返回2个元素的下标,它们满足相加的和为target。
你可以假定每个输入,都会恰好有一个满足条件的返回结果。
时间复杂度n^2
def twosum(nums, target): for i in xrange(len(nums)): for j in xrange(i+1, len(nums)): if (nums[i] + nums[j]) == target: return [i, j]
时间复杂度n(思考一下)
0 0
- LEETCODE 1.Two Sum (python实现)
- 【Leetcode】【Python】【C++】1. Two Sum实现
- leetcode two sum python 实现
- [leetcode]-[Two Sum]-python实现
- Leetcode题解(Python): 1.Two Sum
- LeetCode 1.Two Sum (Python)
- 【leetcode】1. Two Sum(Python & C++)
- 1.Two Sum Leetcode Python
- [Leetcode] 1.Two Sum @python
- LeetCode: 1. Two Sum python
- Leetcode: 1. Two Sum [python]
- [leetcode:python]1.Two Sum
- leetcode 1. Two Sum python
- leetcode:1. Two Sum(Java实现)
- [LeetCode]1 Two Sum(C++,Python实现)
- [leetcode]Two Sum C++ python实现
- leetCode之Two Sum python实现
- 【Leetcode】【python】Two Sum, Two Sum II
- 设计模式之建造者模式
- 单例模式
- 数据库小结
- [读书笔记]Android IPC机制(一)
- Unity3D在android系统下调试
- LEETCODE 1.Two Sum (python实现)
- Mysql——锁、事务与并发控制
- 动态规划 最大子矩阵
- c++中怎么求二维数组的长度
- 协查技巧总结
- Java 鼠标点击事件实例
- 代码重构--大话重构
- c++上机作业6
- Java中获取路径的方法