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. sql datetime类型数据如果进行模糊查询

    select * from Table1 where CONVERT(nvarchar(50),CreateTime,120) like '%2019'

  2. 【C/C++】知识点系统复习 (第一周)

    2018/12/18 周二 1. C++内存布局分为几个区域,每个区域有什么特点? 主要可以分为 5 个区域, (1) 栈区:由编译器自动分配释放,存放函数的参数值,局部变量的值等.其操作方式类似于数 ...

  3. 使用Dockerfile部署TOMCAT

    一.准备工作 1.下载安装docker 2.下载tomcat压缩包 (1)我这里是下载的apache-tomcat-9.0.8.tar.gz 下载地址 https://tomcat.apache.or ...

  4. ubuntu Oracle SQL Developer 安装

    一. 官网下载oracle 安装包 二.下载完毕后,检查你的Ubuntu是否安装了tar和alien sudo apt-get install tar sudo apt-get install ali ...

  5. RCC初始化学习

    一.设置RCC时钟 //#define SYSCLK_HSE #define SYSCLK_FREQ_20MHz //#define SYSCLK_FREQ_36MHz //#define SYSCL ...

  6. 低价购买 (动态规划,变种最长下降子序列(LIS))

    题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...

  7. 【dart学习】之字典(Map)的相关方法总结

    一,概述 通常来讲,Map是一个键值对相关的对象,键和值可以是任何类型的对象.每个键只出现一次,而一个值则可以出现多次.映射是动态集合. 换句话说,Maps可以在运行时增长和缩小. dart:core ...

  8. SCP-Py-001

    项目编号:Py-001 项目等级:Euclid 特殊收容措施: Py-001必须被存储于基金会主站的网络硬盘中,并切断一切与互联网的连接. Py-001突破收容在网络上传播后,一旦在一台计算机上被下载 ...

  9. The Second Scrum Meeting!

    第七周会议 情况简述 会议概要:汇报已完成的任务,讨论并解决遇到的问题 参与人员:詹晓宇  谢赛金  熊紫仁  徐翠萍  周娟  孙尚煜 会议地点:六区研讨性教室 具体内容 小组成员 已完成任务 计划 ...

  10. vue中引入路由,如果你懒得写那么

    可以npm i vue-router --save,项目中自动给你写好,vuex也可以