Skip to content

Commit 1878053

Browse files
author
myLightLin
committed
add
1 parent 6c810e8 commit 1878053

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[easy] 给你一副扑克牌,每张扑克牌上有点数,看能不能把他们分组,使得每组都有相同的点数并且相同的牌数。扑克牌就是数组,点数就是数组中元素大小。<br>
2+
3+
solution: 因为涉及到分组,且每组必须由相同的牌数,那么我们首先就得考虑不同的点数共有多少张,因此可采用 hash 存储, key 值为点数,value 为数组元素<br>
4+
出现的次数,这下知道每张牌出现了多少次了,那么就可以进行分组。分组的规则也很简单,题目要求**要选择大于 2 的能够将正副牌分成一组或者多组的牌数**,<br>
5+
所以可以求这些牌出现的次数的最大公约数,它就是我们要分组的每一组的大小,比如为 2 ,说明每组要有两张牌。那么题目要求 X >= 2 ,所以最后求出来的这个<br>
6+
最大公约数只需大于 2 就可以返回 true 。

数组/914. X of a Kind in a Deck of Cards/solution.js

Whitespace-only changes.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy