Function:

        public static List<int[]> SumSet(int[] array)
{
List<int[]> result = new List<int[]>();
for (int i = 0; i < array.Length; i++)
{
int differ = -array[i];
for (int j = i + 1; j < array.Length; j++)
{
var a = array.Select((chr, index) => new { chr, index }).Where(chr=>chr.chr == differ - array[j]);
if (a.ToList().Count > 0)
{
int[] aa ={ array[i],array[j],a.ToList()[0].chr};
result.Add((aa.OrderBy(n => n)).ToArray());
}
}
}
HashSet<int[]> set = new HashSet<int[]>(result);
result.Clear();
result.AddRange(set);
return result;
}

  

控制台展示:

        static void Main(string[] args)
{
{
Console.WriteLine("请输入数组:");
string ss = Console.ReadLine();
string[] str = ss.Split(',');
int[] arry=new int[str.Count()];
for (int i = 0; i < str.Count(); i++)
{
string sss = str[i];
arry[i] = Convert.ToInt32(sss);
}
Console.WriteLine("满足条件的组合有:");
List<int[]> result = SumSet(arry);
foreach (int[] ar in result)
{
foreach (int i in ar)
{
Console.Write(i);
}
Console.Write("_");
}
Console.ReadLine();
}
}

  

问题点:List<int> 去重复失败。。。。

leetcode系列---3Sum C#code的更多相关文章

  1. leetcode系列---atoiFunction C#code

    Function: /// <summary> /// ToInt /// </summary> /// <param name="str">& ...

  2. CRL快速开发框架系列教程一(Code First数据表不需再关心)

    本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...

  3. 求和问题总结(leetcode 2Sum, 3Sum, 4Sum, K Sum)

    转自  http://tech-wonderland.net/blog/summary-of-ksum-problems.html 前言: 做过leetcode的人都知道, 里面有2sum, 3sum ...

  4. [Leetcode][016] 3Sum Closest (Java)

    题目: https://leetcode.com/problems/3sum-closest/ [标签]Array; Two Pointers [个人分析] 这道题和它的姊妹题 3Sum 非常类似, ...

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

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

  6. 1 翻译系列:什么是Code First(EF 6 Code First 系列)

    原文链接:http://www.entityframeworktutorial.net/code-first/what-is-code-first.aspx EF 6 Code-First系列文章目录 ...

  7. LeetCode 16. 3Sum Closest(最接近的三数之和)

    LeetCode 16. 3Sum Closest(最接近的三数之和)

  8. leetcode 系列文章目录

    leetcode 系列文章目录 0. 两数之和1. 两数相加 2. 无重复字符的最长子串 3. 寻找两个有序数组的中位数 4. 最长回文子串 5. Z 字形变换 6. 整数反转 7. 字符串转换整数 ...

  9. C#刷遍Leetcode系列连载 索引

    C#刷遍Leetcode系列文章 索引 索引(陆续发布中,请保持关注) C#刷遍Leetcode面试题系列连载(1) - 入门与工具简介 C#刷遍Leetcode面试题系列连载(2): No.38 - ...

随机推荐

  1. go 学习笔记之10 分钟简要理解 go 语言闭包技术

    闭包是主流编程语言中的一种通用技术,常常和函数式编程进行强强联合,本文主要是介绍 Go 语言中什么是闭包以及怎么理解闭包. 如果读者对于 Go 语言的闭包还不是特别清楚的话,可以参考上一篇文章 go ...

  2. Spring 梳理-使用<context:property-placeholder>标签导入多个properties文件

    使用<context:property-placeholder>标签导入多个properties文件 2017年12月20日 10:10:36 sf_climber 阅读数:5830更多 ...

  3. if [ $# -ne 1 ] 作用

    在shell脚本中经常会使用if [ $# -ne 1 ];then...这类脚本 ];then 这段命令是用于判断参数的个数是否为1,不是则进行then的逻辑处理,其中$#表示参数个数,-ne是不等 ...

  4. springboot启动报错 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

    新建了一个springboot项目报一下错误: Failed to configure a DataSource: 'url' attribute is not specified and no em ...

  5. [Week 2][Guarantee of PLA] the Correctness Verification of PLA

    Conditions: For the data set D, there exists a $\displaystyle W_{f}$ which satisfies that for every ...

  6. [Vjudge][POJ][Tony100K]搜索基础练习 - 全题解

    目录 POJ 1426 POJ 1321 POJ 2718 POJ 3414 POJ 1416 POJ 2362 POJ 3126 POJ 3009 个人整了一些搜索的简单题目,大家可以clone来练 ...

  7. Vue:获取当前定位城市名

    实现思想:通过定位获取到当前所在城市名: 1.在工程目录index.html中引入: <script type="text/javascript" src="htt ...

  8. Nginx+Tomcat Https SSL部署方案

    1.软件版本: nginx-1.15+ tomcat-8.0+ 2.先解决一个疑问:Tomcat到底需不需要配置SSL? 答案:不需要 3.SSL申请 使用腾讯云.阿里云的服务器,会更加方便申请.(申 ...

  9. 使用 Chrome 对长网页(知乎、微信公众号文章)进行完整截图

    当需要对一个较长的网页进行完整截图时,可以直接使用谷歌浏览器(Chrome)自带的截图功能完成,不需要依赖第三方截图软件. 1. 打开网页 以微信公众号的页面作为示例:https://mp.weixi ...

  10. Django中的表关系实现及操作

    表关系的实现   预备知识 ORM的正向操作和反向操作: 1.正向操作:一个模型中定义了一个外键,通过该模型对该外键操作的操作叫做正向操作. 2.反向操作:被外键所关联的模型,通过该模型对外键所在模型 ...