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. u3d animation运用明细

    u3d的动作legacy模式,经测试得出 using UnityEngine; using System.Collections; public class AnimateCon : MonoBeha ...

  2. mysql使用sql语句查询数据库所有表注释已经表字段注释

    场景: 1. 要查询数据库 "mammothcode" 下所有表名以及表注释 /* 查询数据库 ‘mammothcode’ 所有表注释 */ SELECT TABLE_NAME,T ...

  3. 两台linux服务器之间实现挂载

    https://blog.csdn.net/lpp_dd/article/details/78743862 两台linux服务器之间实现挂载: 服务端: 1.首先需要在主机上设置允许挂载的目录 (1) ...

  4. js eventLoop (使用chunk 同步变异步)

    https://www.cnblogs.com/xiaohuochai/p/8527618.html 线程 javascript是单线程的语言,也就是说,同一个时间只能做一件事.而这个单线程的特性,与 ...

  5. HTML5 FileReader

    利用HTML5中的FileReader类,动态切换af中Panel的背景,动态设置img元素的图片 1 if(FileReader){ 2 $('.panel').on("tap" ...

  6. 通过tarball形式安装HBASE Cluster(CDH5.0.2)——Hadoop NameNode HA 切换引起的Hbase错误,以及Hbase如何基于NameNode的HA进行配置

    通过tarball形式安装HBASE Cluster(CDH5.0.2)——Hadoop NameNode HA 切换引起的Hbase错误,以及Hbase如何基于NameNode的HA进行配置 配置H ...

  7. Oracle-10.2.0.1,打补丁10.2.0.5:在 debian 版本4【不含4】以上,及 ubuntu 7.04【不含7.04】以上都可以安装!

    如题. todo 特殊的:ubuntu 16.04 LTS 版本 无法安装成功,原因待查找!!! 最近测试练习安装linux x64上的 oracle10.2.0.5, 都要吐了.

  8. CDbConnection failed to open the DB connection: could not find driver错误的处理

    在PHP.INI文件中extension=php_pdo_mysql.dll 去掉注释

  9. [Converge] Backpropagation Algorithm

    Ref: CS231n Winter 2016: Lecture 4: Backpropagation Ref: How to implement a NN:中文翻译版本 Ref: Jacobian矩 ...

  10. json_encode让URL内容斜杠/不转义

    同事在开发接口的时候根据接口提示要求传参一个字符串json,该json格式中有URL数组,按照json_encode编码后总发现 http://变成了 http:\/\/  .URL的斜杠自动的被转义 ...