Problem: 给定整数集合,找到所有满足a+b+c=0的元素组合,要求该组合不重复。
 
首先对给出的数组进行排序 Arrays.sort()
从第0个元素开始进行判断,对应的有最大值num[high]
1、当num[low]+num[high]== -num[i]时,此时可以将num[low],num[high],num[i]添加至list中
    a. 当low<high并且num[low]==num[low+1]时,需要考虑到重复问题,因此要进行 low++操作
    b. 当low<high并且num[high]==num[high—]时,同样需要进行去重复操作,进行high—操作
    c. 上述操作结束后需要对low++ ,high—
 
2、当num[low]+num[high]< -num[i]时,需要移动最小值指针 low++
3、当num[low]+num[high]< -num[i]时,需要移动最大值指针 high--
 
参考代码:
package leetcode_50;

/***
*
* @author pengfei_zheng
* 最长公共前缀
*/
public class Solution14 {
public String longestCommonPrefix(String[] strs) {
if(strs == null || strs.length == ) return "";//字符串数组为空或者长度为0
String pre = strs[];
int i = ;
while(i < strs.length){//遍历所有字符串
while(strs[i].indexOf(pre) != )//当前子串不满足前缀
pre = pre.substring(,pre.length()-);//当前子串长度减一
i++;
}
return pre;//返回前缀
}
}
 
 

LeetCode 15 3Sum(3个数求和为0的组合)的更多相关文章

  1. 【LeetCode】15. 3Sum 三个数和为0

    题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find al ...

  2. [LeetCode] 15. 3Sum ☆☆☆(3数和为0)

    描述 Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Fi ...

  3. LeetCode 15 3Sum [sort] <c++>

    LeetCode 15 3Sum [sort] <c++> 给出一个一维数组,找出其中所有和为零的三元组(元素集相同的视作同一个三元组)的集合. C++ 先自己写了一发,虽然过了,但跑了3 ...

  4. [LeetCode] 15. 3Sum 三数之和

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  5. leetcode 15. 3Sum 二维vector

    传送门 15. 3Sum My Submissions Question Total Accepted: 108534 Total Submissions: 584814 Difficulty: Me ...

  6. LeetCode 15. 3Sum 16. 3Sum Closest 18. 4Sum

    n数求和,固定n-2个数,最后两个数在连续区间内一左一右根据当前求和与目标值比较移动,如果sum<target,移动较小数,否则,移动较大数 重复数处理: 使i为左至右第一个不重复数:while ...

  7. LeetCode——15. 3Sum

    一.题目链接:https://leetcode.com/problems/3sum/ 二.题目大意: 3和问题是一个比较经典的问题,它可以看做是由2和问题(见http://www.cnblogs.co ...

  8. Leetcode 15. 3Sum

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  9. Java [leetcode 15] 3Sum

    问题描述: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find ...

随机推荐

  1. 开源项目推荐:e-example / Springboot+bootstrap + ……

    前言: 我想要找一个 springboot + bootstrap 的例子介绍,然后搜索到了这个开源项目. 所有能跑起来的项目都有研究价值,看看这个项目的文档.目前正好满足我想要的功能.推荐 正文: ...

  2. 使用 mysql_use_result 还是使用 mysql_store_result?

    From: http://my.oschina.net/moooofly/blog/186456 本文整理了关于“使用 mysql_use_result 还是 mysql_store_result”的 ...

  3. adb 架构

    adb是什么? adb就是Android调试桥,很形象啊. 先来看adb原理的逻辑图: ADB架构adb由两个物理文件组成:adb/adb.exe运行于PC端,包括Linux.Windows.Mac ...

  4. Android学习笔记——Intents 和 Intent Filters(二)

    本人邮箱:JohnTsai.Work@gmail.com,欢迎交流讨论. 欢迎转载,转载请注明网址:http://www.cnblogs.com/JohnTsai/p/3993488.html 知识点 ...

  5. sql产生随机数

    使用RAND(),结果是类似于这样的随机小数:0.615942003695649 SELECT FLOOR(RAND()*N) ---生成的数是这样的:12.0  SELECT CAST(FLOOR( ...

  6. git branch 命令

    1.git init 该命令执行之后并没有创建branch 2.git add 添加文件,这时branch 也还没生成.git branch name也没用 3.git commit 提交到git r ...

  7. ns-3 的下载、编译以及 Eclipse 的相关配置

    0. 写在前面 对于初次接触Linux系统的人来说,ns-3 的安装似乎并不友好.但其实仅仅要按部就班地来做,其安装过程也没有看上去的那么复杂.本文将官方 Wiki 中的安装过程稍作梳理,希望能为刚開 ...

  8. SpringBoot------使用Fastjson解析Json数据

    方法一: 1.在pom.xml文件下添加依赖包 <dependency> <groupId>com.alibaba</groupId> <artifactId ...

  9. 诡异的DataTime.Now.ToString()

    昨天晚上调程序的时候在服务器上出现这种问题 DataTime.Now.ToString("yyyy-MM-dd HH:mm:ss") 居然出现了2014-8-14 8:nn:14: ...

  10. if条件和for循环语句、while、do..while、switch语法

    //if 语句 ; ) { NSLog(@"不及格"); }) { NSLog(@"及格"); } //if语句 判断条件存在多个情况下,判断一个年是否为润年 ...