LeetCode--No.001 Two Sum
2024-10-15 18:51:02
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 ;
}
}
最新文章
- [LeetCode] Guess Number Higher or Lower II 猜数字大小之二
- Andorid 反编译App
- PDF 补丁丁 0.5.0.2078 测试版发布:不用打字,也能加书签
- zend studio 常用快捷键
- 【转】敏捷开发 Scrum 总结
- GC overhead limit exceeded填坑心得
- sudo: /etc/sudoers is mode 0777, should be 0440终极解决之道
- ztree addNode editName removeNode
- sql CRUD 增删改查复习汇总
- spring3 mvc:方法返回值的学习
- Redis系列-存储篇list主要操作函数小结
- FU-A分包方式,以及从RTP包里面得到H.264数据和AAC数据的方法。。
- Windows Service 之 详解(二)
- 如何彻底解决jsp页面中文乱码及数据库乱码
- ##DAY11 UITableView编辑
- LINUX 硬盘分区及文件系统
- 在Windows上安装Elasticsearch v5.4.2
- nyoj n-1位数
- 02_编写Table的CRUD
- socket.io常用api
热门文章
- EOS keosd
- JPA和SpringData知识梳理
- Pandas排列和随机采样
- 【Django】关于设置和获取cookies
- mysql查询语句中自定义变量(转)
- 【POJ2778】DNA Sequence 【AC自动机,dp,矩阵快速幂】
- Python开发【第六篇】:面向对象
- sqlserver 组内排序
- CentOS7 Failed to start LSB: Bring up/down networking.解决方法
- cmd输入appium-doctor,运行时提示&#39;node&#39;不是内部或外部的命令