public class Solution
{
public bool HasGroupsSizeX(int[] deck)
{
var len = deck.Length;
for (int i = ; i <= len; i++)//i表示每组的卡牌数量
{
if (len % i != )
{
continue;
}
else
{
var pati = len / i;//分组
var list = deck.OrderBy(x => x).ToList();
var num = ;
for (int j = ; j < pati; j++)
{
var patlist = list.Skip(j * i).Take(i).ToList();
var gp = patlist.GroupBy(x => x).Count();
if (gp == )
{
num++;
}
else
{
break;
}
}
if (num == pati)
{
return true;
}
}
}
return false;
}
}

本周的新题目,也是目前easy中的最后一题,算是一个阶段完成了吧。

leetcode914的更多相关文章

  1. [Swift]LeetCode914.一副牌中的X | X of a Kind in a Deck of Cards

    In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...

  2. Leetcode914.X of a Kind in a Deck of Cards卡牌分组

    给定一副牌,每张牌上都写着一个整数. 此时,你需要选定一个数字 X,使我们可以将整副牌按下述规则分成 1 组或更多组: 每组都有 X 张牌. 组内所有的牌上都写着相同的整数. 仅当你可选的 X > ...

随机推荐

  1. C的文件操作函数

    fgetc(FILE *)意为从文件指针stream指向的文件中读取一个字符,读取一个字节后,光标位置后移一个字节fputc(char,FILE*)将字符ch写到文件指针fp所指向的文件的当前写指针的 ...

  2. Hash学习小结

    Hash 简要说明 \(OI\)中一般采用进制\(hash\).模数可以用\(unsigned \ long \ long\)自然溢出,也可以使用大质数.值得一提的是,\(unsigned\ long ...

  3. JS 区分单击双击

    var timeout =null; $("#Btn").on("click",function(){ clearTimeout(timeout);//停止单击 ...

  4. Visual->UIElement->FrameworkElement,带来更多功能的同时也带来了更多的限制

    在 WPF 或 UWP 中,我们平时开发所遇到的那些 UI 控件或组件,都直接或间接继承自 Framework.例如:Grid.StackPanel.Canvas.Border.Image.Butto ...

  5. css设置图片水平及垂直居中

    .box { /*非IE的主流浏览器识别的垂直居中的方法*/ display: table-cell; vertical-align:middle; /*设置水平居中*/ text-align:cen ...

  6. POJ1220 Number Base Conversion

    题意 Write a program to convert numbers in one base to numbers in a second base. There are 62 differen ...

  7. MySQL-Proxy 读写分离、同步延时问题解决方案

    MySQL-Proxy 读写分离.同步延时问题解决方案 使用MySQL将读写请求转接到主从Server. 一 安装MySQL Proxy MySQL Proxy的二进制版非常方便,下载解压缩后即用. ...

  8. 笔记:使用 stylus stylus-loader

    笔记:使用 stylus stylus-loader 安装 stylus Stylus-loader cnpm i stylus stylus-loader --save 配置 webpack.con ...

  9. mysql的partition分区

    前言:当一个表里面存储的数据特别多的时候,比如单个.myd数据都已经达到10G了的话,必然导致读取的效率很低,这个时候我们可以采用把数据分到几张表里面来解决问题.方式一:通过业务逻辑根据数据的大小通过 ...

  10. 3、MR开发入门

    1.预先准备2个文件file1.txt和file2.txt.文件内容为网页上摘下,不具有代表性,只为举例. file1.txt内容为: With this setup, whenever you ch ...