Leetcode 1.Two Sum(java版)
来源:互联网 发布:淘宝衣服换号 编辑:程序博客网 时间:2024/06/05 06:08
题目:
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.
题目大意:
求一个数组中两个元素的下标,这两个元素相加和为target。
example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
思路:
暴力枚举法
代码:
class Solution { public int[] twoSum(int[] nums, int target) { int[] i = new int[2]; for(int x=0;x<nums.length;x++) { for(int j=x+1;j<nums.length;j++) { if(nums[x]+nums[j]==target) { i[0] = x; i[1] = j; break; } } } return i; }}
阅读全文
0 0
- Leetcode 1.Two Sum(java版)
- [LeetCode java] 1.Two Sum
- LeetCode(java)1. Two Sum
- leetcode 1. Two Sum -----java
- (JAVA)LeetCode 1. Two Sum
- LeetCode 1. Two Sum(Java)
- [LeetCode] 1. Two Sum java
- leetcode 1. Two Sum -----java
- 1. Two Sum leetcode java
- LeetCode: Two Sum (Java)
- [Leetcode] Two Sum (Java)
- 【Leetcode】two sum JAVA
- LeetCode java Two Sum
- Two Sum leetcode Java
- [LeetCode][Java] Two Sum
- leetcode:Two Sum 【Java】
- LeetCode|Two Sum-java
- leetcode Two Sum(Java)
- 10.19
- 008-题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。
- 异常和File类
- 基因的庇护 (AC自动机 dp)
- 24点游戏
- Leetcode 1.Two Sum(java版)
- div中使用背景图片
- 完整购物车
- Longest Consecutive Sequence
- 设计模式-结构模式之Facade
- IC射频笔记之——双电容输出匹配好处+最佳带宽取值
- 拦截导弹
- 实现TabLayout+ViewPager+Fragment头目的联动模式
- python函数的返回值