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; + } +} + + 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; + } +} +