LintCode 56- 两数之和
来源:互联网 发布:asp.net编程实战宝典 编辑:程序博客网 时间:2024/05/03 15:52
本人电子系,只是一学生。心悦计算机,小编以怡情。
这道题应该放到入门(沉思状)
给一个整数数组,找到两个数使得他们的和等于一个给定的数 target。
你需要实现的函数twoSum需要返回这两个数的下标, 并且第一个下标小于第二个下标。注意这里下标的范围是 1 到 n,不是以 0 开头。
注意事项
你可以假设只有一组答案。
样例:
给出 numbers = [2, 7, 11, 15], target = 9, 返回 [1, 2].
public int[] twoSum(int[] numbers, int target) { // write your code here int temp[]={0,1}; for(int i=0;i<numbers.length;i++) for(int j=1;j<numbers.length;j++) { if(numbers[i]+numbers[j]==target) { temp[0]=i+1;//正常做,最后找出来都+1便是注意事项的要求 temp[1]=j+1; return temp; } } return temp; }
0 0
- lintcode-两数之和-56
- lintcode,56,两数之和
- LintCode 56- 两数之和
- LintCode 56 两数之和
- lintcode 56 两数之和
- [Lintcode] #56 两数之和
- Lintcode 两数之和
- LintCode 两数之和
- LintCode-两数之和
- LintCode 两数之和
- lintcode--两数之和
- lintcode 两数之和
- LintCode-两数之和
- LintCode 两数之和
- LintCode-剑指Offer-(56)两数之和
- LintCode(56) 两数之和
- lintcode之两数之和
- LintCode(M)两数之和
- 多线程-事件
- 【iOS沉思录】:iOS多媒体音频(上)-音频播放
- win7卸载普通方式无法卸载的软件
- 欢迎使用CSDN-markdown编辑器
- EOJ 1148 质数阵 dfs
- LintCode 56- 两数之和
- jq获取a标签地址
- localhost不能访问127.0.0.1可以访问的原因及解决方法
- 读者写者问题
- Python2代码转为Python3代码
- ubuntu16.04+caffe安装和 py-faster-rcnn的CPU安装
- 从flask学python---从flask v0.1开始---01
- x^n次幂
- Ubuntu16.04+GTX1070+cuda8.0+cudnn5.1配置faster-rcnn的方法