Two Sum

  • Total Accepted: 262258
  • Total Submissions: 1048169
  • Difficulty: Easy

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.

Example:

Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1]. 暴力解法,没有优化思路。
 public class Num1 {
public int[] twoSum(int[] nums, int target) {
int [] res = new int [2] ;
for(int i = 0 ; i < nums.length ; i++){
if(nums[i] > target){
continue ;
}else{
res[0] = i ;
}
for(int j = i+1 ; j < nums.length ; j++){
if((nums[i]+nums[j]) == target){
res[1] = j ;
return res ;
}else{
continue ;
}
}
} return res ;
}
}

最新文章

  1. [LeetCode] Guess Number Higher or Lower II 猜数字大小之二
  2. Andorid 反编译App
  3. PDF 补丁丁 0.5.0.2078 测试版发布:不用打字,也能加书签
  4. zend studio 常用快捷键
  5. 【转】敏捷开发 Scrum 总结
  6. GC overhead limit exceeded填坑心得
  7. sudo: /etc/sudoers is mode 0777, should be 0440终极解决之道
  8. ztree addNode editName removeNode
  9. sql CRUD 增删改查复习汇总
  10. spring3 mvc:方法返回值的学习
  11. Redis系列-存储篇list主要操作函数小结
  12. FU-A分包方式,以及从RTP包里面得到H.264数据和AAC数据的方法。。
  13. Windows Service 之 详解(二)
  14. 如何彻底解决jsp页面中文乱码及数据库乱码
  15. ##DAY11 UITableView编辑
  16. LINUX 硬盘分区及文件系统
  17. 在Windows上安装Elasticsearch v5.4.2
  18. nyoj n-1位数
  19. 02_编写Table的CRUD
  20. socket.io常用api

热门文章

  1. EOS keosd
  2. JPA和SpringData知识梳理
  3. Pandas排列和随机采样
  4. 【Django】关于设置和获取cookies
  5. mysql查询语句中自定义变量(转)
  6. 【POJ2778】DNA Sequence 【AC自动机,dp,矩阵快速幂】
  7. Python开发【第六篇】:面向对象
  8. sqlserver 组内排序
  9. CentOS7 Failed to start LSB: Bring up/down networking.解决方法
  10. cmd输入appium-doctor,运行时提示&#39;node&#39;不是内部或外部的命令