1 Two Sum
// Java
public int[] twoSum(int[] nums, int target) {
int[] answer = new int[2];
for (int i = 0; i < nums.length; i ++) {
int j = i + 1;
for (; j < nums.length; j ++) {
if (nums[i] + nums[j] == target) {
answer[0] = i;
answer[1] = j;
return answer;
}
}
}
return answer;
}
1 Two Sum的更多相关文章
- LeetCode - Two Sum
Two Sum 題目連結 官網題目說明: 解法: 從給定的一組值內找出第一組兩數相加剛好等於給定的目標值,暴力解很簡單(只會這樣= =),兩個迴圈,只要找到相加的值就跳出. /// <summa ...
- 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 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- BZOJ 3944 Sum
题目链接:Sum 嗯--不要在意--我发这篇博客只是为了保存一下杜教筛的板子的-- 你说你不会杜教筛?有一篇博客写的很好,看完应该就会了-- 这道题就是杜教筛板子题,也没什么好讲的-- 下面贴代码(不 ...
- [LeetCode] Path Sum III 二叉树的路径和之三
You are given a binary tree in which each node contains an integer value. Find the number of paths t ...
- [LeetCode] Partition Equal Subset Sum 相同子集和分割
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
- [LeetCode] Split Array Largest Sum 分割数组的最大值
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
- [LeetCode] Sum of Left Leaves 左子叶之和
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...
- [LeetCode] Combination Sum IV 组合之和之四
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
随机推荐
- LEMP安装脚本
#!/bin/bash#LEMP Serverumount /dev/cdrommount /dev/cdrom /mediaIOS="/etc/yum.repos.d/rhel-debug ...
- metasploit用法
1.msfconsole 进入metasploit 2.help connect 查看帮助 3.msfcli -h 查看帮助 4.ms08_067_netapi O 字符命令后加“O”,查看配置 5. ...
- JAVA IO 学习
Java流的分类 1.输入/输出流 输入流:只能向其读数据,不能写. 输出流:只能向其写数据,不能读. 所谓的输入输出都是相对应用程序而言的. 2.字节流/字符流 单位不同,字节流操作8位,字符流操作 ...
- (Hibernate进阶)Hibernate映射——多对多关联映射(八)
多对多映射是现实生活中最常见的映射,也是最容易理解的映射.废话少说,直接开始. 映射原理 不论是单向关联还是双向关联都是通过第三张表,将两个表中的主键放到第三张做一个关联.用第三张表来解决可能会造成数 ...
- PSP个人项目耗时记录
估计这个任务需要多少时间: 计划 估计用时 估计这个任务需要多少时间 500min 开发 450min 需求分析 120min 生成设计文档 20min 设计复审 30miin 代码规范 10min ...
- linux 配置 tomcat 自动发布脚本
首先将打包好的 war 包(举例 management-20160809-1.0.war),传到 tomcat 的 webapps 目录下,然后在 tomcat 目录下新建 deploy.sh 脚本. ...
- java学习第20天(IO流)
构造方法File file = new File("e:\\demo"); 创建文件夹 File file = new File("e:\\demo"); fi ...
- Spring boot开发过程遇到的一些小问题
1.无法将yml文件自动注入到对应的类的实例中去: pom.xml文件里没有加如下依赖 <dependency> <groupId>org.springframework.bo ...
- Google黑板报: 数学之美系列(网上找的原链接)
转载地址:http://blog.sina.com.cn/s/blog_47cccb02010009u0.html 系列一 -- 统计语言模型 http://googlechinablog.com/2 ...
- performSelector和respondsToSelector用法
一.performSelector调用和直接调用区别 下面两段代码都在主线程中运行,我们在看别人代码时会发现有时会直接调用,有时会利用performSelector调用,今天看到有人在问这个问题,我便 ...