LeetCode Array Easy 1. Two Sum
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的更多相关文章
- 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 ...
- LeetCode Array Easy 268. Missing Number
Description Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one th ...
- LeetCode Array Easy 88. Merge Sorted Array
Description Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted ar ...
- LeetCode Array Easy 53. Maximum Subarray 个人解法 和分治思想的学习
Description Given an integer array nums, find the contiguous subarray (containing at least one numbe ...
- LeetCode Array Easy 485. Max Consecutive Ones
Description Given a binary array, find the maximum number of consecutive 1s in this array. Example 1 ...
- 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 ...
- 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 ...
- 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 ...
- LeetCode Array Easy 219. Contains Duplicate II
---恢复内容开始--- Description Given an array of integers and an integer k, find out whether there are two ...
随机推荐
- IIS Express 不允许的父路径
IIS Express 启动一个asp的网站,出现一个错误 Active Server Pages 错误 'ASP 0131' 不允许的父路径 对于IIS可以在可视化的IIS Manager中配置: ...
- JAVA中的SimpleDateFormat yyyy和YYYY的区别
最近有一个功能是对输入的日期格式化,设计给出的范例是 YYYY-MM-dd HH:mm:ss,于是我简单验证了一下是可以的,然后就这么在手册里写了.然后偶然发现有地方也用yyyy啊,这个到底有神马区别 ...
- 转载 初学者必看——最简单最清晰的Struts2项目搭建流程
https://blog.csdn.net/key0323/article/details/50773499 在项目中想要使用Struts2框架,我该怎么做?从哪里开始?这是我的疑惑,我想也是很多初学 ...
- jquery实现左侧菜单 效果
html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...
- firefox下jquery ajax 返回 [object XMLDocument]处理
在firefox下使用jquery ajax处理 返回json类型的时候,ajax执行成功返回结果为 [object XMLDocument]. 处理办法:在getWriter.write():前面加 ...
- 每天一个linux命令:cp(8)
cp cp命令用来将一个或多个源文件或者目录复制到指定的目的文件或目录.它可以将单个源文件复制成一个指定文件名的具体的文件或一个已经存在的目录下.cp命令还支持同时复制多个文件,当一次复制多个文件时, ...
- 二分图最大权匹配——KM算法
前言 这东西虽然我早就学过了,但是最近才发现我以前学的是假的,心中感慨万千(雾),故作此篇. 简介 带权二分图:每条边都有权值的二分图 最大权匹配:使所选边权和最大的匹配 KM算法,全称Kuhn-Mu ...
- 【Flutter学习】之 Flutter 的生命周期
一,概述 Flutter 的生命周期分为两个部分: Widget 的生命周期 App 的生命周期 二,Widget 的生命周期 Flutter 里的 Widget 分为 StatelessWidget ...
- 判断系统是否安装了flash插件
方法1: uses comobj; procedure TForm1.Button1Click(Sender: TObject); var v:variant; begin v:=CreateOleO ...
- [bzoj2456]mode 题解
改题改自闭的时候当然要靠水题来调节心情(逃 2456: mode Time Limit: 1 Sec Memory Limit: 1 MBSubmit: 8461 Solved: 3171[Sub ...