(LeetCode)Two Sum
来源:互联网 发布:sketch 46 破解版 mac 编辑:程序博客网 时间:2024/04/30 07:26
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 class Solution { public int[] twoSum(int[] numbers, int target) { int [] result = new int[2]; success: for(int i = 0; i < numbers.length; i++) for(int j = i+1; j < numbers.length; j++){ if(numbers[i]+numbers[j] == target){ result[0] = i+1; result[1] = j+1; break success; } } return result; }}
0 0
- 【Leetcode】Two Sum (Sum)
- LeetCode: Two Sum
- LeetCode: Two Sum
- [Leetcode] Two Sum
- LeetCode : Two Sum
- Leetcode: Two Sum
- leetcode 46: Two Sum
- [LeetCode] Two Sum
- LeetCode 1 - Two Sum
- Leetcode : Two Sum
- 【leetcode】Two Sum
- [LeetCode]Two Sum
- leetcode Two Sum
- [Leetcode] Two Sum
- [leetcode] Two Sum
- LeetCode - Two Sum
- leetcode之Two Sum
- LeetCode | Two Sum
- 第17周项目27-软件比拼
- 【GUI组件】按钮Button
- WDF
- centos-6.5 修改系统日志时间戳格式
- Direct3D学习手记一:实现Direct3D程序框架
- (LeetCode)Two Sum
- 植物 動物 사람의 發生 (韓長庚 易學原理總論)
- C# 获取文件名及扩展名
- 64位系统下的"fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏“解决方案
- 英雄会第二届在线编程大赛·线上初赛:AB 题解
- 旅游定机票
- 从零搭建Android框架Android-Tractor(三) 模式选择
- 一分钟了解pagerank最基本原理
- AE开发:如何设置图层符号