From 3523cecba3ab0b90a14fad3f5fe4c2000c3196aa Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:11:13 +0900 Subject: [PATCH 1/2] Create 4092. Binary Digit Score --- .../4092. Binary Digit Score" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/4092. Binary Digit Score" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/4092. Binary Digit Score" "b/leetcode3/\354\240\225\354\247\204\354\230\201/4092. Binary Digit Score" new file mode 100644 index 00000000..6905125d --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/4092. Binary Digit Score" @@ -0,0 +1,35 @@ +/** + * @param {number} a + * @param {number} b + * @return {number} + */ +var calculateScore = function(a, b) { + /* + - a, b toString 사용해서 이진수 변환 + - 1의 개수 : s1, s2 + */ + + let score = 0; + let s1 = 0; + let s2 = 0; + + for (let i = 0; i < a.toString(2).length; i++){ + if (a.toString(2)[i] == 1){ + s1++; + } + } + + for (let i = 0; i < b.toString(2).length; i++){ + if (b.toString(2)[i] == 1){ + s2++; + } + } + + if (s1 >= s2){ + score = s1 * s2; + } else if (s1 < s2){ + score = Math.floor(s2 / s1); + } + + return score; +}; From 9610d8a05bac1c922366ef54eb159d80ae8dace9 Mon Sep 17 00:00:00 2001 From: Jinyoung Jeong <80400463+jyoung2419@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:36:46 +0900 Subject: [PATCH 2/2] Add minLights function for road illumination Implement function to calculate minimum lights needed to illuminate a road based on given positions. --- ...3964. Minimum Lights to Illuminate a Road" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "leetcode3/\354\240\225\354\247\204\354\230\201/3964. Minimum Lights to Illuminate a Road" diff --git "a/leetcode3/\354\240\225\354\247\204\354\230\201/3964. Minimum Lights to Illuminate a Road" "b/leetcode3/\354\240\225\354\247\204\354\230\201/3964. Minimum Lights to Illuminate a Road" new file mode 100644 index 00000000..6e73008c --- /dev/null +++ "b/leetcode3/\354\240\225\354\247\204\354\230\201/3964. Minimum Lights to Illuminate a Road" @@ -0,0 +1,43 @@ +/** + * @param {number[]} lights + * @return {number} + */ +var minLights = function(lights) { + /* + lights[3] = 2 + max(0,1) ~ min(4,5) 1 부터 4까지 => 0에 설치 + lights[i] = 0 + max(0,0) min(3,0) + + - 작동하지 않는 전구 위치를 찾아야 함 + - 다 0인 배열 chk + - for문 돌면서 if (lights[i] == v)이면 max(0,i-v)~min(n-1,i+v)까지 체크 + */ + + let n = lights.length + let chk = Array(n).fill(0); + let cnt = 0; + + for (let i = 0; i < n; i++){ + if (lights[i] != 0){ + let v = lights[i]; + for (let k = Math.max(0, i-v); k <= Math.min(n-1, i+v); k++){ + chk[k] = 1; + } + } + } + + for (let i = 0; i < n; i++){ + if (chk[i] == 0){ + let j = Math.min(n-1, i+1); + + cnt++; + + for (let k = Math.max(0, j-1); k <= Math.min(n-1, j+1); k++){ + chk[k] = 1; + } + } + } + + return cnt; +};