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. Spring 梳理 - javaConfig在App和webApp中的应用

    package com.dxz.demo.configuration; import org.springframework.context.annotation.Configuration; @Co ...

  2. Spring MVC-从零开始-未完待续

    Spring MVC 之 json格式的输入和输出 Spring定时器简单使用 Spring mvc 拦截器的简单使用 Spring MVC文件上传

  3. SD-WAN 配置及应用模板**(二)

    目录 0. 前言 1. 配置模板 1.1 创建各类 'Feature' 模板: 1.1.1 添加波特率模板 1.1.2 添加 'VPN0' 模板 1.1.3 添加 'VPN10' 模板 1.1.4 添 ...

  4. RBD 基本使用 - Storage6

    块存储管理系列文章 (1)RBD 基本使用 - Storage6 (2)iSCSI 网关管理 (3)使用 librbd 将虚拟机运行在 Ceph RBD (4)RBD Mirror 容灾 Ceph 块 ...

  5. redis 漏洞造成服务器被入侵-CPU飙升

    前言   前几天在自己服务器上搭了redis,准备想着大展身手一番,昨天使用redis-cli命令的时候,10s后,显示进程已杀死.然后又试了几次,都是一样的结果,10s时间,进程被杀死.这个时候我还 ...

  6. ef core实现无感知软删除

    很多web程序一般的偶不会设计真的物理删除了. 基本上都是在在数据库加一个标记,就得当作已经删除了.同时在查询的时候,过滤已经标记删除的数据 ef core实现软删除是非常简单的,直接在OnModel ...

  7. css3:bacground-size

    个人博客: https://chenjiahao.xyz CSS3之背景尺寸Background-size是CSS3中新加的一个有关背景的属性,这个属性是改变背景尺寸的通过各种不同是属性值改变背景尺寸 ...

  8. Jenkins设置BUILD NUMBER初始值

    由于服务器迁移,需要将之前的Jenkins构建项目一并迁移,为了区分构建编号,需要将所有项目的BUILDE NUMBER 初始值定义. 网上有一些资料是更新单个项目的,我们这项目几百个,所以只好自己研 ...

  9. Color Length UVALive - 5841

    题文:见网页:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=sho ...

  10. stm32填坑之旅 - stm32f103c8t6点亮板载贴片蓝色LED

    转载请注明:https://www.cnblogs.com/rockyf/p/11691622.html 开篇 开篇一定要精彩,不然路人不理睬!下述是笔者作为arm小白的填坑之旅 没错,这个之前一直从 ...