leetcode系列---3Sum C#code
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的更多相关文章
- leetcode系列---atoiFunction C#code
Function: /// <summary> /// ToInt /// </summary> /// <param name="str">& ...
- CRL快速开发框架系列教程一(Code First数据表不需再关心)
本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...
- 求和问题总结(leetcode 2Sum, 3Sum, 4Sum, K Sum)
转自 http://tech-wonderland.net/blog/summary-of-ksum-problems.html 前言: 做过leetcode的人都知道, 里面有2sum, 3sum ...
- [Leetcode][016] 3Sum Closest (Java)
题目: https://leetcode.com/problems/3sum-closest/ [标签]Array; Two Pointers [个人分析] 这道题和它的姊妹题 3Sum 非常类似, ...
- LeetCode 15 3Sum [sort] <c++>
LeetCode 15 3Sum [sort] <c++> 给出一个一维数组,找出其中所有和为零的三元组(元素集相同的视作同一个三元组)的集合. C++ 先自己写了一发,虽然过了,但跑了3 ...
- 1 翻译系列:什么是Code First(EF 6 Code First 系列)
原文链接:http://www.entityframeworktutorial.net/code-first/what-is-code-first.aspx EF 6 Code-First系列文章目录 ...
- LeetCode 16. 3Sum Closest(最接近的三数之和)
LeetCode 16. 3Sum Closest(最接近的三数之和)
- leetcode 系列文章目录
leetcode 系列文章目录 0. 两数之和1. 两数相加 2. 无重复字符的最长子串 3. 寻找两个有序数组的中位数 4. 最长回文子串 5. Z 字形变换 6. 整数反转 7. 字符串转换整数 ...
- C#刷遍Leetcode系列连载 索引
C#刷遍Leetcode系列文章 索引 索引(陆续发布中,请保持关注) C#刷遍Leetcode面试题系列连载(1) - 入门与工具简介 C#刷遍Leetcode面试题系列连载(2): No.38 - ...
随机推荐
- (java实现)单链表
什么是单链表 在了解单链表之前,你知道什么是链表吗?如果你不知道什么是链表,可以看看我的这篇博客<链表-LinkList> 单链表是链表的其中一种基本结构.一个最简单的结点结构如图所示,它 ...
- Kubernetes 系列(六):Kubernetes部署Prometheus监控
1.创建命名空间 新建一个yaml文件命名为monitor-namespace.yaml,写入如下内容: apiVersion: v1 kind: Namespace metadata: name: ...
- VR应用评测 - Luna
Luna http://store.steampowered.com/app/605770/Luna/ Steam VR 2017年10月发布 | 开发者:Funomena | 好评率92% 一款制作 ...
- TP5安装workerman版本的坑
今天想在TP5上安装workerman,用于个人学习,然后悲剧的是,第一步就卡住了,根据手册里说的首先通过composer安装 composer require topthink/think-work ...
- [TLSR8267] 泰凌微 telink tlsr8267 ble ADC 用法浅谈
1.读 datasheet 在<DS_TLSR8267-E21_Datasheet for Telink BLE SoC TLSR8267.pdf>第11章详细介绍了ADC相关属性及参数. ...
- Flutter 的基本控件
文本控件 Text 支持两种类型的文本展示,一个是默认的展示单一样式文本 Text,另一个是支持多种混合样式的富文本 Text.rich. 单一样式文本 Text 单一样式文本 Text 的初始化,是 ...
- 将jar包发布到maven的中央仓库细节整理
在学习springboot框架的时候,会引入各种各样的starter依赖,照着教程尝试写了个demo-spring-boot-stater,可以理解为一个组件,随引随用 但是只能自己引用,无法共享,于 ...
- SQL SERVER 字符串类型varchar格式转换成int类型进行排序
日常数据分析过程中,经常会遇到排序的情况,有时会根据空字段表进行临时排序,转换数据类型 使用 ORDER BY CAST (<字段名> AS INT) ASC 举例: SELECT I ...
- taro taroUi的H5打包后路径/修改为./
打包文件路径修改在config/index.tsx中,如下 esnextModules: ['taro-ui'],配置也需要在h5中写入并且将publicPath: './'即可,不需要在做一个h ...
- 基于powershell的socks代理
0x01 前言 在实战中,内网的代理尤其重要,而常见的端口转发被反病毒软件已经盯死,那么学习使用基于powershell的渗透脚本进行代理.端口转发的非常有必要的. 0x02 使用 介绍ithub: ...