From ee5a1ecef6038e8b127d1561e20a8bfcda28c3c6 Mon Sep 17 00:00:00 2001 From: donghyeon95 Date: Sat, 1 Feb 2025 00:26:18 +0900 Subject: [PATCH 1/2] feat: Number of 1 Bits #232 --- number-of-1-bits/donghyeon95.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 number-of-1-bits/donghyeon95.java diff --git a/number-of-1-bits/donghyeon95.java b/number-of-1-bits/donghyeon95.java new file mode 100644 index 000000000..4a93019b8 --- /dev/null +++ b/number-of-1-bits/donghyeon95.java @@ -0,0 +1,15 @@ +class Solution { + public int hammingWeight(int n) { + int mask = 1; + int result = 0; + while(n>0) { + if ((n & mask) == 1) { + result++; + } + n = n >> 1; + } + + return result; + } +} + From 5ed7b79e16bb2cbe6b32754506890ca78b68c415 Mon Sep 17 00:00:00 2001 From: donghyeon95 Date: Sat, 1 Feb 2025 13:19:20 +0900 Subject: [PATCH 2/2] feat: Longest Repeating Character Replacement #244 --- .../donghyeon95.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 longest-repeating-character-replacement/donghyeon95.java diff --git a/longest-repeating-character-replacement/donghyeon95.java b/longest-repeating-character-replacement/donghyeon95.java new file mode 100644 index 000000000..816403dca --- /dev/null +++ b/longest-repeating-character-replacement/donghyeon95.java @@ -0,0 +1,45 @@ +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +class Solution { + public int characterReplacement(String s, int k) { + // K개까지는 용인되는 최대 길이를 구해라 + // 2 포인터 => 최대 O(2*N) = O(N) + // 용인 되는 길이면 second++, 용인되는 길이가 아니면 first++; + + String[] strings = s.split(""); + HashMap strCnt = new HashMap<>(); + int result = 0; + int first = 0; + int second = 0; + + while(first strCnt) { + int total = 0; + int max = 0; + for (int a: strCnt.values()) { + total += a; + max = Math.max(max, a); + } + return total - max; + } +} + +