[ 命名建議 ] LeetCode 914. X of a Kind in a Deck of Cards #128
Answered
by
twy30
LPenny-github
asked this question in
Q&A
-
|
LeetCode: 再麻煩 @twy30 給予命名建議 orz 感激不盡 大大新年快樂! using System.Collections.Generic;
using System.Numerics;
public class Solution
{
public bool HasGroupsSizeX(int[] deck)
{
if (deck.Length <= 1) { return false; }
Dictionary<int, BigInteger> dictionary = new Dictionary<int, BigInteger>();
for (int i = 0; i < deck.Length; ++i)
{
if (dictionary.ContainsKey(deck[i]))
{
++dictionary[deck[i]];
}
else
{
dictionary.Add(deck[i], 1);
}
}
BigInteger gcd = dictionary.GetEnumerator().Current.Value;
foreach (var value in dictionary.Values)
{
gcd = BigInteger.GreatestCommonDivisor(gcd,value);
}
return gcd >= 2;
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
twy30
Feb 13, 2021
Replies: 1 comment 1 reply
-
|
你好,新年快樂 😊 Dictionary<int, BigInteger> dictionary = new Dictionary<int, BigInteger>();這個可以改成 public bool HasGroupsSizeX(int[] deck)原題將這個 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
LPenny-github
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@LPenny-github
你好,新年快樂 😊
這個可以改成
cardCounts。原題將這個
int[]參數命名為deck「一副 (牌)」 ;我覺得cards「牌」會更適合。