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 = [, , , ], target = ,

Because nums[] + nums[] =  +  = ,
return [, ].

给定一个数组和一个目标,计算数组中任意两个数的和,如果等于目标,则返回这两个数字的下标

C#实现

public class Solution {
public int[] TwoSum(int[] nums, int target) {
int[] result = new int[];
for(int i = ; i< nums.Length - ; i++){
for(int j = i+; j < nums.Length; j++){
if((nums[i] + nums[j]) == target){
result[]= i;
result[] = j;
}
}
}
return result;
}
}

结束

LeetCode Array Easy 1. Two Sum的更多相关文章

  1. LeetCode Array Easy 167. Two Sum II - Input array is sorted

    Description Given an array of integers that is already sorted in ascending order, find two numbers s ...

  2. LeetCode Array Easy 268. Missing Number

    Description Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one th ...

  3. LeetCode Array Easy 88. Merge Sorted Array

    Description Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted ar ...

  4. LeetCode Array Easy 53. Maximum Subarray 个人解法 和分治思想的学习

    Description Given an integer array nums, find the contiguous subarray (containing at least one numbe ...

  5. LeetCode Array Easy 485. Max Consecutive Ones

    Description Given a binary array, find the maximum number of consecutive 1s in this array. Example 1 ...

  6. LeetCode Array Easy 448. Find All Numbers Disappeared in an Array

    Description Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear ...

  7. LeetCode Array Easy 414. Third Maximum Number

    Description Given a non-empty array of integers, return the third maximum number in this array. If i ...

  8. LeetCode Array Easy 283. Move Zeroes

    Description Given an array nums, write a function to move all 0's to the end of it while maintaining ...

  9. LeetCode Array Easy 219. Contains Duplicate II

    ---恢复内容开始--- Description Given an array of integers and an integer k, find out whether there are two ...

随机推荐

  1. Java技术中的三大特性

    1.虚拟机                                Java虚拟机JVM(Java Virtual Machine)在Java编程里面具有非常重要的地位,约相当于前面学到的Jav ...

  2. 中文字符集编码unicode,gb2312,cp936,GBK,GB18030介绍

    概要: UTF-8的一个特别的好处是它与ISO- 8859-1完全兼容,可以表示世界上所有的字符,汉字通常用3个字节来表示.GB2312的code page是CP20936.GBK的code page ...

  3. Spring学习笔记(14)——注解零配置

    我们在以前学习  Spring  的时候,其所有的配置信息都写在  applicationContext.xml  里,大致示例如下: java代码: <beans> <bean n ...

  4. JS面向对象——构造函数模型

    ECMAScript中的构造函数可用来创建特定类型的对象.我们可以创建自定义构造函数,从而定义对象类型的属性和方法,解决工厂模型中对象识别的问题. <!DOCTYPE html> < ...

  5. mac OS 安装 Homebrew及常用命令

    Homebrew  是由国外大神 Max Howell 开发的一款包管理工具,类似Debian的apt,他可以安装任何你想安装的东西. 安装方法 命令行输入 /usr/bin/ruby -e &quo ...

  6. java一个数组的内存图

  7. 最大流的EK算法模板

    模板题:洛谷p3376 题目大意: 给出一个网络图,以及其源点和汇点,求出其网络最大流. 基本思路: 套模板 EK的时间复杂度O(V*E^2) EK算法思路: 1.通过BFS拓展合法节点(每个节点在本 ...

  8. Electron-vue实战(三)— 如何在Vuex中管理Mock数据

    Electron-vue实战(三)— 如何在Vuex中管理Mock数据 作者:狐狸家的鱼 本文链接:Vuex管理Mock数据 GitHub:sueRimn 在vuex中管理mock数据 关于vuex的 ...

  9. python利用ConfigParser读写配置文件

    ConfigParser 是Python自带的模块, 用来读写配置文件, 用法非常简单. 配置文件的格式是: []包含的叫section,    section 下有option=value这样的键值 ...

  10. Java 的内置对象

    1.Request对象 该对象封装了用户提交的信息,通过调用该对象相应的方法可以获取封装的信息,即使用该对象可以获取用户提交的信息.    当Request对象获取客户提交的汉字字符时,会出现乱码问题 ...