From f820a64a9a182b2377dec7fb7341a7707029d361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=97=BC=ED=98=9C=EC=A0=95?= <122238744+cyzlcyzl@users.noreply.github.com> Date: Wed, 12 Aug 2026 18:04:11 +0900 Subject: [PATCH] Create 914. X of a Kind in a Deck of Cards.java --- .../914. X of a Kind in a Deck of Cards.java" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "leetcode3/\354\227\274\355\230\234\354\240\225/914. X of a Kind in a Deck of Cards.java" diff --git "a/leetcode3/\354\227\274\355\230\234\354\240\225/914. X of a Kind in a Deck of Cards.java" "b/leetcode3/\354\227\274\355\230\234\354\240\225/914. X of a Kind in a Deck of Cards.java" new file mode 100644 index 00000000..9e710a78 --- /dev/null +++ "b/leetcode3/\354\227\274\355\230\234\354\240\225/914. X of a Kind in a Deck of Cards.java" @@ -0,0 +1,25 @@ +// O(nlogn) + +import java.util.Arrays; + +class Solution { + public boolean hasGroupsSizeX(int[] deck) { + Arrays.sort(deck); + + int g = 0; + int count = 1; + for (int i = 1; i <= deck.length; i++) { + if (i < deck.length && deck[i] == deck[i - 1]) { + count++; + } else { + g = gcd(g, count); + count = 1; + } + } + return g >= 2; + } + + private int gcd(int a, int b) { + return b == 0 ? a : gcd(b, a % b); + } +}