Leetcode-1:Two Sum
来源:互联网 发布:mac如何用搜狗输入法 编辑:程序博客网 时间:2024/06/12 20:40
Question:
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.
给定一个整数数组和一个目标数字,使得数组中的两个元素之和等于目标数字。
你可以假定每个输入都有一个确切的解决方案,你不可以使用相同的元素两次。
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
Answer:
public class Solution { public int[] TwoSum(int[] nums, int target){ for (int i = 0; i < nums.length; i++) { for (int j = i + 1; j < nums.length; j++) { if (nums[j] == target - nums[i]) { return new int[] { i, j }; } } } return null; }}
阅读全文
0 0
- LeetCode 1 - Two Sum
- leetcode 1 Two Sum
- Leetcode【1】:Two Sum
- [leetcode 1] Two Sum
- 【leetcode-1】Two Sum
- [leetcode 1] Two Sum
- [Leetcode] 1 - Two Sum
- LeetCode (1) Two Sum
- LeetCode 1:《Two Sum》
- LeetCode | #1 Two Sum
- leetcode-1 Two Sum
- Two Sum | LeetCode(1)
- [Leetcode]1Two Sum
- leetcode 1 Two Sum
- leetcode #1 Two Sum
- leetcode 1:Two Sum
- LeetCode 1 Two Sum
- leetcode #1 two sum
- php实现字符串翻转,使字符串的单词正序,单词的字符倒序
- HDU 6035 Colorful Tree(树形dp)
- iMX6Q调试篇-Linux程序开发使用gdb调试
- 开发微信支付所碰过的壁
- WPF跨线程调用和Dispatcher
- Leetcode-1:Two Sum
- altas mysql-proxy安装配置
- 方法重写与方法重载
- String类的常用方法
- MVC入门 从Controller到VIew 之间传值学习
- WisKey的眼神(GCD)
- Java中用Ehcache做缓存处理
- 重置Mac“活动监视器”
- 剑指Offer——链表中倒数第K个节点