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. Recursion in Java

    Recursion in Java 递归无出口 public class RecursionExample1 { public static void p() { System.out.println ...

  2. TCP/IP重新学习

    TCP/IP 是用于因特网 (Internet) 的通信协议. 1.什么是TCP/IP? TCP/IP 是供已连接因特网的计算机进行通信的通信协议. TCP/IP 指传输控制协议/网际协议(Trans ...

  3. GDB 调试工具高级用法

    解决core核心文件转出问题 ulimit -c #查看core文件的生成开关,若为0则关闭 ulimit -c unlimited #打开开关,只在当前shell生效 sudo sh -c 'ech ...

  4. braft初探

    接上一篇<brpc初探>. 什么是RAFT 看内部一个开源项目的时候,一开始我以为他们自己实现了raft协议.但是看了代码之后,发现用的是braft.因为在我们自己bg里一直在提paxos ...

  5. Ubuntu系统安装网易云音乐、搜狗输入法

    这两个软件都很良心,提供了Ubuntu版本,直接下载安装即可. 网易云音乐: 下载-打开-安装 http://music.163.com/#/download 搜狗拼音输入法 下载-打开-安装 htt ...

  6. BZOJ1073 k短路(A*算法)

    A*算法,也叫启发式搜索,就是设计一个预估函数,然后在搜索的过程中进行有序的搜索,我们设到目前状态的花费为f(x),到目标状态的估计花费为h(x),那么我们按照h(x)+f(x)排序即可,这道题里起点 ...

  7. bzoj 5294: [Bjoi2018]二进制

    Description pupil 发现对于一个十进制数,无论怎么将其的数字重新排列,均不影响其是不是333 的倍数.他想研究对于二进 制,是否也有类似的性质.于是他生成了一个长为n 的二进制串,希望 ...

  8. 2018/3/13 noiρ[rəʊ]模拟赛 125分

    T1 60分暴力,水分也不会水,打表也不会打,正解是不可能写正解的,这辈子都写不出来正解的,虽然是zz题但是也拿不到分这样子. 正解:(啥?正解是sb组合数?这都他娘的想不到,真鸡儿丢人我自杀吧.) ...

  9. JZYZOJ1525 HAOI2012道路 堆优化的dijkstra+pair

    From Tyvj Guest ☆[haoi2012]道路                 描述 Description     C国有n座城市,城市之间通过m条单向道路连接.一条路径被称为最短路,当 ...

  10. [YC703]ゴミ拾い Easy

    [YC703]ゴミ拾い Easy 题目大意: 二维平面内有\(n(n\le3\times10^5)\)个人和\(n\)个物品,第\(i\)个人在\((a_i,0)\)上,第\(i\)个物品在\((x_ ...