From 2b91c5967f98e52cde1a6976eec4c5d66378bad9 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, 14 Oct 2026 23:39:52 +0900 Subject: [PATCH] Create 4065. Rearrange Array by Removing Distinct Values.java --- ...ge Array by Removing Distinct Values.java" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "leetcode3/\354\227\274\355\230\234\354\240\225/4065. Rearrange Array by Removing Distinct Values.java" diff --git "a/leetcode3/\354\227\274\355\230\234\354\240\225/4065. Rearrange Array by Removing Distinct Values.java" "b/leetcode3/\354\227\274\355\230\234\354\240\225/4065. Rearrange Array by Removing Distinct Values.java" new file mode 100644 index 00000000..f5b91bfe --- /dev/null +++ "b/leetcode3/\354\227\274\355\230\234\354\240\225/4065. Rearrange Array by Removing Distinct Values.java" @@ -0,0 +1,24 @@ +class Solution { + public int[] rearrangeArray(int[] nums) { + int[] count = new int[101]; + int maxCount = 0; + + for (int num : nums) { + count[num]++; + maxCount = Math.max(maxCount, count[num]); + } + + int[] answer = new int[nums.length]; + int index = 0; + + for (int round = 1; round <= maxCount; round++) { + for (int value = 1; value <= 100; value++) { + if (count[value] >= round) { + answer[index++] = value; + } + } + } + + return answer; + } +}