博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
3Sum
阅读量:4075 次
发布时间:2019-05-25

本文共 789 字,大约阅读时间需要 2 分钟。

3Sum

Given an array S of n integers, are there elements abc in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.

Note:

  • Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c)
  • The solution set must not contain duplicate triplets.

For example, given array S = {-1 0 1 2 -1 -4},    A solution set is:    (-1, 0, 1)    (-1, -1, 2)
Java代码:

public class Solution {    public List
> threeSum(int[] num) { if (num == null) return null; List
> result = new ArrayList
>(); int len = num.length; // Sort Arrays.sort(num); for (int i=0; i
l = new ArrayList
(); l.add(num[i]); l.add(num[j]); l.add(num[k]); result.add(l); // Bypass second and third elements int K = k; while (k

转载地址:http://anuni.baihongyu.com/

你可能感兴趣的文章
看出在玩啥了吗?想不想体验下
查看>>
Time.deltaTime 的平均值在0.1-0.2左右
查看>>
向量加减法运算及其几何意义
查看>>
magnitude是精确距离,sqrMagnitude是节省CPU的粗略距离,精度有损失
查看>>
学习和研究下unity3d的四元数 Quaternion
查看>>
一些最最基本的几何图形公式
查看>>
Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported in Unity 5.
查看>>
理解四元数的一些文章
查看>>
Unity Shader入门
查看>>
片元着色器(Fragment Shader)被称为像素着色器(Pixel Shader),但
查看>>
UNITY自带的3D object没有三角形?
查看>>
Lambert(朗伯)光照模型 和Half Lambert的区别
查看>>
float4数据类型
查看>>
【Unity Shaders】学习笔记
查看>>
Holographic Remoting Player
查看>>
unity之LOD
查看>>
UNITY 移动到指定位置的写法
查看>>
Unity中关于作用力方式ForceMode的功能注解
查看>>
UNITY实现FLASH中的setTimeout
查看>>
HOLOLENS 扫描特效 及得出扫描结果(SurfacePlane)
查看>>