博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode 1 Two Sum
阅读量:7110 次
发布时间:2019-06-28

本文共 767 字,大约阅读时间需要 2 分钟。

hot3.png

Given an array of integers, find two numbers such that they add up to a specific target number.

The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.

You may assume that each input would have exactly one solution.

Input: numbers={2, 7, 11, 15}, target=9

Output: index1=1, index2=2

public int[] twoSum(int[] nums, int target) {    for(int i = 0 ; i < nums.length -1 ; i++){       for(int j = i+1 ; j < nums.length ; j++){           if(nums[i]+nums[j]==target){               return new int[]{i+1,j+1};           }       }         }        return null;}

转载于:https://my.oschina.net/bobingxin/blog/471661

你可能感兴趣的文章
基于vue的h5文件切片上传(获取文件md5,实现秒传、进度条实现)
查看>>
让XP远程支持网络身份验证
查看>>
spark运用逻辑回归算法操作Titanic数据集
查看>>
阿里云maven镜像
查看>>
Silverlight MVVM 贴近实战(一)
查看>>
Java标准输入输出+基础理论+基本数据类型总结
查看>>
poj 1088 滑雪
查看>>
如何学习图算法
查看>>
springmvc @RequestBody @ResponseBody的作用
查看>>
专利缴费信息网上补充及管理系统--操作指南
查看>>
Linux下定时重启tomcat脚本
查看>>
蹦极-打破人生惯性
查看>>
微服务架构设计基础之领域驱动设计
查看>>
IntelliJ IDEA编译Android项目比Eclipse慢
查看>>
安易硬盘数据恢复软件v8.81官方版
查看>>
Maven使用图示-关于生命周期、命令行和IDEA插件
查看>>
数据库登录密码不同时,可在文件data ==》config.php修改密码
查看>>
非递归实现后序遍历二叉树
查看>>
开发人员转型到管理者必须学会的7件事
查看>>
rsync从Windows到Linux的同步备份
查看>>