package com.company;

import java.util.LinkedList;
import java.util.List; public class Main { public int[] twoSum(int[] numbers, int target) {
int i = 0, j = numbers.length - 1;
int []ret = new int[2];
while (i < j) {
if (numbers[i] + numbers[j] < target) {
i++;
}
else if (numbers[i] + numbers[j] > target) {
j--;
}
else {
ret[0] = i+1;
ret[1] = j+1;
break;
}
}
return ret;
} public static void main(String[] args) {
// write your code here
System.out.println("Hello"); int []numbers = {2, 7, 11, 15};
int target = 9;
Main mn = new Main();
int[] ret = mn.twoSum(numbers, target);
System.out.printf("ret: %d, %d\n", ret[0], ret[1]); }
}

leetcode mock interview-two sum II的更多相关文章

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

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

  2. leetcode & Mock Interview

    leetcode & Mock Interview https://leetcode.com/interview/ xgqfrms 2012-2020 www.cnblogs.com 发布文章 ...

  3. 【LeetCode】113. Path Sum II 解题报告(Python)

    [LeetCode]113. Path Sum II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fu ...

  4. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  5. [Leetcode][Python]40: Combination Sum II

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 40: Combination Sum IIhttps://oj.leetco ...

  6. 【一天一道LeetCode】#113. Path Sum II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  7. 【一天一道LeetCode】#40. Combination Sum II

    一天一道LeetCode系列 (一)题目 Given a collection of candidate numbers (C) and a target number (T), find all u ...

  8. 【LeetCode】40. Combination Sum II (2 solutions)

    Combination Sum II Given a collection of candidate numbers (C) and a target number (T), find all uni ...

  9. 【LeetCode】113. Path Sum II

    Path Sum II Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals ...

  10. [LeetCode] Nested List Weight Sum II 嵌套链表权重和之二

    Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...

随机推荐

  1. jvisualvm 远程连接jboss

    由于项目中使用jboss 作为web容器,每当项目上线时需要使用loadrunner对项目进行性能压测,这时就需要实时观察JVM的一些参数.想使用jvisualvm借助jstatd远程连接服务器上面的 ...

  2. 【js】两个数相除有余数时结果加1

    var all=15; var item=2; var pages=all%item==0?(all/item):(Math.floor(all/item)+1); console.log(pages ...

  3. Gitlab基本管理(二)

    一. Gitlab分支 1. 切换到项目位置. 2. 创建一个项目的一新分支. mike@win10-001 MINGW64 ~/cookbook/cookbook (master) $ git br ...

  4. sublime 字体设置

    安装完成sublime之后,推荐一种比较舒服的字体设置,个人习惯.配置步骤如下,打开sublime-->Preferences-->Settings - User 2.复制以下内容粘贴,并 ...

  5. The dd command of linux

    The dd command stands for "data duplicator" and used for copying and converting data. It i ...

  6. JAVA基础关键字小结一

    基础部分总是看起来简单,若要明白原理和使用场景,需要慢慢的体会. 本文对常用的关键字如final,transient,volatile,static以及foreach循环的原理重新梳理了一遍. 一.f ...

  7. php获取当前域名、主机、URL、端口、参数、网址、路径、代理等【转】

    <?php //获取域名或主机地址 echo $_SERVER['HTTP_HOST']."<br />"; //获取网页地址 echo $_SERVER['PH ...

  8. Linux下burg引导

    用得比较久了,比grub顺手: 安装: sudo add-apt-repository ppa:n-muench/burg; sudo apt-get update; sudo apt-get ins ...

  9. QTREEⅠ SPOJ

    树剖模板,注意把边化为点后要查到y的儿子. #include<bits/stdc++.h> using namespace std; ; int f[N],bel[N],w[N],id[N ...

  10. 我的OI生涯 第五章

    我的OI生涯 第五章 千古诗才,蓬莱文章建安骨 一身傲骨,青莲居士谪仙人 李白追月逆江河 包黑斩龙顺民心 豪气压群雄,能使力士脱靴,贵妃捧砚; 仙才媲众美,不让参军俊逸,开府清新 我辈此中惟饮酒 先生 ...