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 ...
随机推荐
- css 图片有间隔多个Img标签之间的间隙
今天写css时发现,图片加起来刚好是900px的三张图片,不能在一个900px宽容器放下,因为图片之间有间隔,我猜是浏览器把两个img标签之间的空格当成了空白节点. 在网上找到了几个不错的解决方法: ...
- windows修改docker的默认存放位置
docker默认存储到c盘,我需要移动到其他盘. 参考了网上很多资料,结果要么移动不了,要么重启docker就回到c盘了. 最后参考docker的官方论坛,找到了解决方案.https://forums ...
- 饿汉单例模式 and 懒汉单例模式
饿汉单例模式:主要就是利用static关键字,在类加载的时候生成实例,调用效率高 但是如果一直没有调用getInstance方法的话,就会造成资源浪费 具体实现如下: class Single{ pr ...
- 2018-8-10-wpf-绑定-DataGridTextColumn-
title author date CreateTime categories wpf 绑定 DataGridTextColumn lindexi 2018-08-10 19:16:53 +0800 ...
- Linux: 给右键菜单加一个“转换图片为jpg格式”
Linux上通常都会安装imagemagick这个小巧但又异常强大的工具.这个软件提供了一系列很好用的功能.这里说一说如何使用它的convert命令转换图片为jpg格式,以及如何把它添加到Thunar ...
- Node.js的适用场景?
1).实时应用:如在线聊天,实时通知推送等等(如socket.io) 2).分布式应用:通过高效的并行I/O使用已有的数据 3).工具类应用:海量的工具,小到前端压缩部署(如grunt),大到桌面图形 ...
- tomcat manager 禁止外网访问 只容许内网访问
参考:http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html A default Tomcat installation includes ...
- vue学习笔记(五)— 组件通信
关于vue父子组件通信 作者:狐狸家的鱼 本文链接:vue组件通信 GitHub:sueRimn 如果组件是一个单页面,组件之间存在父子关系,数据传递就需要根据父子不同的地位使用不同的办法. 借助新建 ...
- Python 序列类型拆包 %s 和'{}'.format 的功能差异之一
>>> 1, 2, 3 #这样写成一行相当于一个元组(1, 2, 3)>>> x = 1, 2, 3>>> x(1, 2, 3)>>& ...
- Python每日一题 006
题目 你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小. 如果只是单纯的通过将图片缩放到iPhone5分辨率大小,显然最后呈现出来的效果会很糟糕.所以等比例缩放到长( ...