leetcode1
public class Solution
{
public int[] TwoSum(int[] nums, int target)
{
var ary = new int[];
for (int i = ; i < nums.Length; i++)
{
for (int j = i + ; j < nums.Length; j++)
{
if (nums[i] + nums[j] == target)
{
ary[] = i;
ary[] = j;
return ary;
}
}
}
return ary;
}
}
https://leetcode.com/problems/two-sum/#/description
补充一个python的实现:
class Solution:
def twoSum(self, nums: 'List[int]', target: 'int') -> 'List[int]':
s = {}
for i in range(len(nums)):
n = nums[i]
cop = target - n
if cop in s.keys():
return [s[cop],i]
s[nums[i]] = i
return []
leetcode1的更多相关文章
- Leetcode1——两数之和 详细解析
Leetcode1--两数之和 题目分类:数组.哈希表的应用 1. 题目描述 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数 ...
- Count Complete Tree Nodes || LeetCode1
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * s ...
- LeetCode1:Two Sum
题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...
- leetcode1:在数组中找2个数的和正好等于一个给定值--哈希
package java_net_test; import java.util.HashMap; import java.util.Iterator; import java.util.Map; pu ...
- LeetCode1 Two Sum
题目 :Given an array of integers, return indices of the two numbers such that they add up to a specifi ...
- leetcode-1 Two Sum 找到数组中两数字和为指定和
问题描写叙述:在一个数组(无序)中高速找出两个数字,使得两个数字之和等于一个给定的值.如果数组中肯定存在至少一组满足要求. <剑指Offer>P214(有序数组) <编程之美& ...
- Leetcode-1.两数之和
题目描述: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数 ...
- [Swift]LeetCode1 .两数之和 | Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- leetcode1:两数之和
给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 实例: 给定 nums = [2, 7, 11, 15],target = ...
随机推荐
- SharePoint Framework 基于团队的开发(一)
博客地址:http://blog.csdn.net/FoxDave SharePoint Framework是新的用来构建SharePoint自定制的开发模型,它专注于客户端开发并用热门的开源工具gu ...
- .Net Core 控制台程序生产exe
打开csproj ,添加一行 <RuntimeIdentifier>win10-x64</RuntimeIdentifier> 具体如下: <Project Sdk=&q ...
- Android:layout属性大全
Android layout属性大全 第一类:属性值 true或者 false android:layout_centerHrizontal 水平居中android:layout_centerVert ...
- Matlab_audiowrite_音频生成
输出音频文件所需函数为 audiowrite .通过例程进行解释: % 生成时间序列 fs = 5000; % [Hz] 信号采样频率 T = 1; % [s] 信号长度 x = 0:1/fs:T; ...
- manhattan plots in qqplot2
###manhattan plots in qqplot2library(ggplot2)setwd("~/ncbi/zm/XPCLR/")read.table("LW. ...
- php连接redis服务
$redis = new Redis(); $redis->connect('127.0.0.1', 6379);//可以执行redis操作了.....
- c#获取汉字首字母拼音
/* * 由SharpDevelop创建. * 用户: lenovo * 日期: 2013/10/22 * 时间: 20:15 * * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件 */ ...
- QT4.8.6-VS2010开发环境配置
目录 1.下载软件 2.环境配置 3.VAssistX配置 1.下载软件 VS2010下载地址:链接: https://pan.baidu.com/s/1gvPjZWBtSEwW37H1xf2vbA ...
- poj2228 Naptime【(环结构)线性DP】
Naptime Time Limit: 1000MS Memory Limit: 65536K Total Submissions:3374 Accepted: 1281 Descriptio ...
- Eclipse Java EE IDE for Web Developers集成的Maven 3 指向自己安装的 Maven
一.配置Maven环境 1.下载apache-maven文件,选择自己需要的版本,地址:Apache 官方下载地址是http://maven.apache.org/download.cgi 2.下载并 ...