From 9e687e8db998c91f9d9baff36d319f8fdfe29928 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:26:23 +0900 Subject: [PATCH 1/2] Create 4092. Binary Digit Score.py --- .../4092. Binary Digit Score.py" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/4092. Binary Digit Score.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/4092. Binary Digit Score.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/4092. Binary Digit Score.py" new file mode 100644 index 00000000..ddf28a47 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/4092. Binary Digit Score.py" @@ -0,0 +1,22 @@ +# + +''' +1. 아이디어 : + + +2. 시간복잡도 : + O(1) + +3. 자료구조/알고리즘 : + + +''' +class Solution: + def calculateScore(self, a: int, b: int) -> int: + def count_set_bits(num): + return bin(num)[2:].count("1") + + a_bin = count_set_bits(a) + b_bin = count_set_bits(b) + return a_bin * b_bin if a_bin >= b_bin else int(b_bin / a_bin) + From 454530fb018c42407aea028e7ab2fd7e3d75e6e0 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:28:03 +0900 Subject: [PATCH 2/2] Create 3964. Minimum Lights to Illuminate a Road.py --- ...4. Minimum Lights to Illuminate a Road.py" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/3964. Minimum Lights to Illuminate a Road.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/3964. Minimum Lights to Illuminate a Road.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/3964. Minimum Lights to Illuminate a Road.py" new file mode 100644 index 00000000..6b9e2a72 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/3964. Minimum Lights to Illuminate a Road.py" @@ -0,0 +1,45 @@ +# + +''' +1. 아이디어 : +왼쪽에서 순회, 오른쪽에서 순회하면서 불이 켜져있는 곳들을 체크합니다. +불이 꺼져 있는 곳(i)들에 대해 i+1에 불을 켜서 최대로 불을 키게(i, i+1, i+2)합니다. + +2. 시간복잡도 : + O(n + n + n) + +3. 자료구조/알고리즘 : +- + +''' +class Solution: + def minLights(self, lights: list[int]) -> int: + n = len(lights) + lit = [0] * n + + distance = 0 + for i in range(n): + distance = max(distance-1, lights[i] +1 if lights[i] > 0 else 0) + if distance > 0: + lit[i] = 1 + + distance = 0 + for i in range(n-1, -1, -1): + distance = max(distance-1, lights[i] +1 if lights[i] > 0 else 0) + if distance > 0: + lit[i] = 1 + + # print(lit) + + ans = 0 + for i in range(n): + if lit[i] != 0: + continue + + pos = min(i+1, n-1) + for j in range(max(0, pos-1), min(n, pos+2)): + lit[j] = 2 + ans+=1 + # print(lit) + return ans +