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的更多相关文章

  1. Leetcode1——两数之和 详细解析

    Leetcode1--两数之和 题目分类:数组.哈希表的应用 1. 题目描述 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数 ...

  2. Count Complete Tree Nodes || LeetCode1

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * s ...

  3. LeetCode1:Two Sum

    题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...

  4. leetcode1:在数组中找2个数的和正好等于一个给定值--哈希

    package java_net_test; import java.util.HashMap; import java.util.Iterator; import java.util.Map; pu ...

  5. LeetCode1 Two Sum

    题目 :Given an array of integers, return indices of the two numbers such that they add up to a specifi ...

  6. leetcode-1 Two Sum 找到数组中两数字和为指定和

     问题描写叙述:在一个数组(无序)中高速找出两个数字,使得两个数字之和等于一个给定的值.如果数组中肯定存在至少一组满足要求. <剑指Offer>P214(有序数组) <编程之美& ...

  7. Leetcode-1.两数之和

    题目描述: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数 ...

  8. [Swift]LeetCode1 .两数之和 | Two Sum

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  9. leetcode1:两数之和

    给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 实例: 给定 nums = [2, 7, 11, 15],target = ...

随机推荐

  1. java中main函数的String[] args

    写java程序时main函数必须有一个字符串数组即String[] args 作用:用来获取用户从命令行输入的参数 如果main函数中不写字符串数组,则将会报错

  2. 2018年4月中旬的PTA(三)

    C高级第三次PTA作业(1) 题目6-1 输出月份英文名 1.设计思路 (1)算法(子函数) 第一步:定义字符型一级指针子函数名getmonth,形参整型n. 第二步:定义长度为12的字符数组指针mo ...

  3. Spring boot JPA 用自定义主键策略 生成自定义主键ID

    最近学习Spring boot JPA 学习过程解决的一些问题写成随笔,大家一起成长.这次遇到自定义主键的问题 package javax.persistence; public enum Gener ...

  4. JavaBasic_11

    Object默认的实现是比较对象的地址 Object默认的实现是比较对象的地址局部内部类 局部位置内部类:局部是指方法体中 1.可以直接访问外部类的成员(这个特征是所有内部类所共有) 2.可以创建内部 ...

  5. spring boot 项目无法访问静态页面

  6. https加载非https资源时不出现问题

    老规矩,国服第一博客copy王,原文链接:https://blog.csdn.net/zhengbingmei/article/details/81325325将系统变成了https访问之后,发现部分 ...

  7. 关于eclipse项目创建maven项目目录不正常的解决方案

    最近学习ssh和maven,遇到了很多问题····首先一个很基础的问题就是我搭建的maven项目目录和教程上的不一样.我的目录之前是这样的: 而教程里的是这样的========> 因为是跟着视频 ...

  8. CORS(跨域资源共享)的防御机制

    一.为什么会出现CORS: 浏览器的同源策略给WEB开发人员带来了巨大的痛苦,信息的交互共享本来就是网络的意义.所以妥协之后出现了CORS. 二.技术原理: 1.简单跨域: (1)方法要求:只能是GE ...

  9. Go Example--格式化字符串

    package main import ( "fmt" "os" ) type point struct { x, y int } func main() { ...

  10. 访问google提示"您的连接不是私密连接"

    直接访问google 提示这个,连subject 也变成连baidu 您的连接不是私密连接 攻击者可能会试图从 www.google.com 窃取您的信息(例如:密码.通讯内容或信用卡信息).了解详情 ...