leetcode mock interview-two sum II
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的更多相关文章
- 乘风破浪:LeetCode真题_040_Combination Sum II
乘风破浪:LeetCode真题_040_Combination Sum II 一.前言 这次和上次的区别是元素不能重复使用了,这也简单,每一次去掉使用过的元素即可. 二.Combination Sum ...
- leetcode & Mock Interview
leetcode & Mock Interview https://leetcode.com/interview/ xgqfrms 2012-2020 www.cnblogs.com 发布文章 ...
- 【LeetCode】113. Path Sum II 解题报告(Python)
[LeetCode]113. Path Sum II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fu ...
- 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 ...
- [Leetcode][Python]40: Combination Sum II
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 40: Combination Sum IIhttps://oj.leetco ...
- 【一天一道LeetCode】#113. Path Sum II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【一天一道LeetCode】#40. Combination Sum II
一天一道LeetCode系列 (一)题目 Given a collection of candidate numbers (C) and a target number (T), find all u ...
- 【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 ...
- 【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 ...
- [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. ...
随机推荐
- Linux的shell终端常用快捷键
参考: http://www.360doc.com/content/17/0627/09/44797135_666854802.shtml https://linux.cn/article-5660- ...
- Laravel 之父:让 Laravel、Symfony、 Zend 来一场公平的性能测试
网上充斥着各式各样的 PHP 框架性能对比的文章.然而,他们总是把“苹果”和“橘子”做对比(看上去有点儿像,都是圆的,但其实不是一码事).这次,我将着重对 Laravel.Symfony 和 Zend ...
- pycharm中在andconda环境中配置pyqt环境
一般在andconda环境中,自带pyqt5 在pip install pyqt5之后,需要安装pyqt5_tools. 对于pycharm需要配置pyqt Designer和pyqt UIC. De ...
- 洛谷P3201 [HNOI2009]梦幻布丁 [链表,启发式合并]
题目传送门 梦幻布丁 题目描述 N个布丁摆成一行,进行M次操作.每次将某个颜色的布丁全部变成另一种颜色的,然后再询问当前一共有多少段颜色.例如颜色分别为1,2,2,1的四个布丁一共有3段颜色. 输入输 ...
- Python的扩展接口[3] -> Matlab引擎 -> 使用 Python 调用 Matlab 程序
Python - Matlab 目录 Python-Matlab 引擎 Python-Matlab 数组 Python-Matlab 基本操作 Python-Matlab 调用 m 文件 Matlab ...
- 趴一趴京东的Ajax动态价格页面
AJAX,异步加载技术!!! 之前在网上看过很多朋友有一种疑问,为什么在看京东网页的源代码里面看不到价格或则折扣一类的数据,而在网页上正常显示却能看到?...之前我也没有想到是AJAX,因为我写写爬虫 ...
- python中对list去重的多种方法
今天遇到一个问题,用了 itertools.groupby 这个函数.不过这个东西最终还是没用上. 问题就是对一个list中的新闻id进行去重,去重之后要保证顺序不变. 直观方法 最简单的思路就是: ...
- Linux下解压缩 - 中文解决方案
命令行工具 Unar 以及 Lsar 安装:sudo apt-get install unar: 预览压缩包:lsar example.zip 解压缩:unar example.zip 指定位置解压: ...
- loj115 无源汇有上下界可行流
link 题意&题解 code: #include<bits/stdc++.h> #define rep(i,x,y) for (int i=(x);i<=(y);i++) ...
- [CC-ANUCBC]Cards, bags and coins
[CC-ANUCBC]Cards, bags and coins 题目大意: 给你\(n(n\le10^5)\)个数,\(q(q\le30)\)次询问,问从中选取若干个数使得这些数之和为\(m(m\l ...