public class TwoSum1 {
public static void main(String[] args) {
int[] nums = new int[]{2, 7, 11, 15};
int target = 9;
int a[] = new int[2];
a = twoSum(nums, target);
System.out.println(a[0]+"----------"+a[1]);
} public static int[] twoSum(int[] nums,int target){
int[] a = 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){
a[0]=i;
a[1]=j; return a;
}
}
}
return a;
}
}

Leetcode:1. Two Sum的更多相关文章

  1. LeetCode:40. Combination Sum II(Medium)

    1. 原题链接 https://leetcode.com/problems/combination-sum-ii/description/ 2. 题目要求 给定一个整型数组candidates[ ]和 ...

  2. leetcode:Minimum Path Sum(路线上元素和的最小值)【面试算法题】

    题目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right w ...

  3. LeetCode:39. Combination Sum(Medium)

    1. 原题链接 https://leetcode.com/problems/combination-sum/description/ 2. 题目要求 给定一个整型数组candidates[ ]和目标值 ...

  4. Python解Leetcode: 1. Two Sum

    题目描述:求出数组中等于目标值的两个数的索引,假定肯定存在两个数并且同一个索引上的数不能用两次. 思路: 用空间换时间,使用一个字典存储已经遍历的数字的索引,如果新遍历的数字和target的差值在字典 ...

  5. 乘风破浪:LeetCode真题_040_Combination Sum II

    乘风破浪:LeetCode真题_040_Combination Sum II 一.前言 这次和上次的区别是元素不能重复使用了,这也简单,每一次去掉使用过的元素即可. 二.Combination Sum ...

  6. 乘风破浪:LeetCode真题_039_Combination Sum

    乘风破浪:LeetCode真题_039_Combination Sum 一.前言     这一道题又是集合上面的问题,可以重复使用数字,来求得几个数之和等于目标. 二.Combination Sum ...

  7. LeetCode 2 Add Two Sum 解题报告

    LeetCode 2 Add Two Sum 解题报告 LeetCode第二题 Add Two Sum 首先我们看题目要求: You are given two linked lists repres ...

  8. leetcode:Roman to Integer(罗马数字转化为罗马数字)

    Question: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the rang ...

  9. leetcode 练习1 two sum

    leetcode 练习1  two sum whowhoha@outlook.com 问题描述 Given an array of integers, return indices of the tw ...

随机推荐

  1. [原创]java WEB学习笔记33:Session 案例 之 购物车

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  2. [原创]关于在CentOS 7.0 下 安装nfs ,遇见 Transaction check error问题的解决

    今天小弟的同学在使用阿里云的服务器安装nfs的时候,出现了一下问题 Transaction check error: file /usr/lib/systemd/system/blk-availabi ...

  3. Delphi 函数的重载和作用域

    1.在delphi 中,我们可以使用相同的函数名来调用不同的函数,我们称这个函数为重载,函数的参数类型和参数的个数可以不同,用到的关键字overload:格式如下: function addInt(x ...

  4. ELK初步指南

    ELK的简单科普文章,加入了自己的一些理解. 内容包括ELK的基本介绍, 应用场景, 架构设计, 监控及自监控, 业界进展及推荐资料等. 用户故事 场景一 作为一个运维工程师, 某天虚拟机出现故障, ...

  5. Shiro-Permissions 对权限的深入理解

    单个权限 query单个资源多个权限 user:query user:add 多值 user:query,add单个资源所有权限 user:query,add,update,delete user:* ...

  6. 学习c++的优秀博客(转)

    http://zhedahht.blog.163.com/  本博客讨论程序员面试题,并主要集中在C/C++.数据结构算法和算法上.http://saturnman.blog.163.com/ sat ...

  7. C语言小程序(七)、石头剪刀布

    本来挺简单的一个程序,但突然想把<Friends>给糅合进去,就多花了一些心思,这是我写过最有趣的程序了. #include <stdio.h> #include <st ...

  8. [转]为什么GOF的23种设计模式里面没有MVC?

    GoF (Gang of Four,四人组, <Design Patterns: Elements of Reusable Object-Oriented Software>/<设计 ...

  9. mesos的zookeeper变更

    采用rpm方式安装你了mesos,碰到zookeeper(采用了cloudera的zookeeper)的IP地址变化了,肿么办? 在master机器中: /etc/mesos/zk进行编辑修改zk路径 ...

  10. POJ1456:Supermarket

    浅谈堆:https://www.cnblogs.com/AKMer/p/10284629.html 题目传送门:http://poj.org/problem?id=1456 把物品按照时间排序,显然\ ...