[LeetCode][1 Two Sum]Java实现
来源:互联网 发布:如何删除mac版office 编辑:程序博客网 时间:2024/06/06 00:25
原题
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.
示例
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1]
这题非常简单,不赘述!
public class Solution1 { public int[] twoSum(int[] nums, int target) { int[] ret = new int[2]; for (int i = 0; i < nums.length; i++) for (int j = i + 1; j < nums.length;j++ ) { if ((nums[i] + nums[j]) == target) { ret[0] = i; ret[1] = j; return ret; } } return ret; }}
阅读全文
0 0
- [LeetCode][1]Two Sum解析 -Java实现
- LeetCode[1] Two Sum (java实现)
- [LeetCode][1 Two Sum]Java实现
- LeetCode(1) Two Sum实现
- LeetCode 1 Two sum Java
- [leetcode-1]Two Sum(java)
- LeetCode 1 - Two Sum ( JAVA )
- LeetCode【1】-Two Sum JAVA
- leetcode#1-Two Sum-java
- LeetCode【1】. Two Sum--java的不同方法实现
- LeetCode-java实现-T1-Two Sum
- LeetCode ---- Two Sum (Java Lua 实现)
- leetcode:1. Two Sum(Java实现)
- java 实现leetcode Two Sum II
- LeetCode: Two Sum (Java)
- [Leetcode] Two Sum (Java)
- 【Leetcode】two sum JAVA
- LeetCode java Two Sum
- 输出前k大的数
- Linux 中 ls 命令 -d -l 参数讲解
- !浏览器的工作原理:新式网络浏览器幕后揭秘
- 657. Judge Route Circle
- 软件工程课程实验报告:实验一
- [LeetCode][1 Two Sum]Java实现
- 做任何事都是一个过程
- Redis 数据类型
- 浅谈css引入方式:link与@import的区别
- A*算法的简单运用
- 人工智能的应用
- java获取某段时间内的所有日期
- 更新python2.7.3后安装pip,steuptools等工具
- 解决redis服务端不能任意ip访问的问题