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. linux用户帐号管理/etcpasswd 和/etc/shadow文件

    #学习鸟哥的linux私房菜 /etc/passwd的文件构造: dahu@dahu-OptiPlex-:~/myfile/VideoFile$ head /etc/passwd root:x:::r ...

  2. 【LOJ】#2350. 「JOI 2017/2018 决赛」月票购买

    题解 首先求一个最短路图出来,最短路图就是这条边在最短路上就保留,否则就不保留,注意最短路图是一个有向图,一条边被保留的条件是 dis(S,u) + val(u,v) = dis(v,T)我们需要求两 ...

  3. 程序员必备的代码审查(Code Review)清单

    在我们关于高效代码审查的博文中,我们建议使用一个检查清单.在代码审查中,检查清单是一个非常好的工具——它们保证了审查可以在你的团队中始终如一的进行.它们也是一种保证常见问题能够被发现并被解决的便利方式 ...

  4. Python加密模块-pycryptodome

    这个模块可以避开Pycrypto安装时带来的一系列包依赖问题. 安装命令: pip install pycryptodome 使用实例: from Crypto.Cipher import AES k ...

  5. java.io.BufferedWriter API 以及源码解读

    下面是java se 7 API 对于java.io.BufferedWriter 继承关系的描述. BufferedWriter可以将文本写入字符流.它会将字符缓存,目的是提高写入字符的效率. bu ...

  6. 【JAVAWEB学习笔记】11_XML

    今日内容介绍 编写服务器软件,访问指定配置内容 访问tomcat下已经发布的web项目 今日内容学习目标 可以编写xml存放任意内容 通过DTD约束编写指定格式的XML 通过Schema约束编写指定格 ...

  7. 51nod 1962区间计数(单调栈加二分)

    题目要求是求出两个序列中处于相同位置区间并且最大值相同的区间个数,我们最直观的感受就是求出每个区间的最大值,这个可以O(N)的求,利用单调栈求出每个数作为最大值能够覆盖的区间. 然后我们可以在进行单调 ...

  8. 【20181027T3】山河令【DP套DP】

    原题 [错解] 一眼DP 哎好像能删成奇形怪状的 弃疗,主要是没时间了 [正解] 神仙DP 明显先设\(f(i,j)\)表示把\([i,j]\) 取完的最小代价 然后发现转移不了,因为可以拿很多块 但 ...

  9. [POJ1205]Water Treatment Plants

    题目大意: 有一排n个格子,要在它们上面装管道. 每个格子上的管道都是T形的,但是可以有三种流动的方向. 每种都是把两个方向的水往另一个方向排出. 如果方向是向左或向右,就是排到相邻的格子里. 特别地 ...

  10. hdu 4352 数位dp+nlogn的LIS

    题意:求区间L到R之间的数A满足A的的数位的最长递增序列的长度为K的数的个数. 链接:点我 该题的关键是记录LIS的状态,学习过nlogn解法的同学都知道,我们每次加入的元素要和前面的比对替换,这里就 ...