μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- java
- Get
- redux-saga
- 맀μΌλ©μΌ
- νλ‘κ·Έλλ¨Έμ€
- ν μ½ν μ½
- μκ³ λ¦¬μ¦
- maeil-mail
- Python
- 리μ‘νΈ
- axios
- react
- νν΄99
- μλ°
- νν΄νλ¬μ€
- C++
- redux-toolkit
- μ΄μ½ν
- react-redux
- redux
- SW
- json-server
- JavaScript
- programmers
- μ½λ©ν μ€νΈν©κ²©μλκΈ°
- react-router
- useDispatch
- sw expert academy
- Algorithm
- createSlice
- Today
- Total
Binary Journey
[ν μ½ν μ½1.5 1-01] λμμ μ¬μκΈ° λ³Έλ¬Έ
[ν μ½ν μ½1.5 1-01] λμμ μ¬μκΈ°
binaryJournalist 2025. 1. 12. 18:02π‘ν μ½ν μ½ μμ¦ 1.5 1ν λͺ¨μ off-site λ¬Έμ νμ΄μ λλ€. (2025.01.12)
λ¬Έμ
μΆμ²: νλ‘κ·Έλλ¨Έμ€ - PCCP κΈ°μΆλ¬Έμ 01. λμμ μ¬μκΈ°
λ΄μ©
λΉμ μ λμμ μ¬μκΈ°λ₯Ό λ§λ€κ³ μμ΅λλ€. λΉμ μ λμμ μ¬μκΈ°λ 10μ΄ μ μΌλ‘ μ΄λ, 10μ΄ νλ‘ μ΄λ, μ€νλ 건λλ°κΈ° 3κ°μ§ κΈ°λ₯μ μ§μν©λλ€. κ° κΈ°λ₯μ΄ μννλ μμ μ λ€μκ³Ό κ°μ΅λλ€.
- 10μ΄ μ μΌλ‘ μ΄λ: μ¬μ©μκ° "prev" λͺ λ Ήμ μ λ ₯ν κ²½μ° λμμμ μ¬μ μμΉλ₯Ό νμ¬ μμΉμμ 10μ΄ μ μΌλ‘ μ΄λν©λλ€. νμ¬ μμΉκ° 10μ΄ λ―Έλ§μΈ κ²½μ° μμμ μ²μ μμΉλ‘ μ΄λν©λλ€. μμμ μ²μ μμΉλ 0λΆ 0μ΄μ λλ€.
- 10μ΄ νλ‘ μ΄λ: μ¬μ©μκ° "next" λͺ λ Ήμ μ λ ₯ν κ²½μ° λμμμ μ¬μ μμΉλ₯Ό νμ¬ μμΉμμ 10μ΄ νλ‘ μ΄λν©λλ€. λμμμ λ¨μ μκ°μ΄ 10μ΄ λ―Έλ§μΌ κ²½μ° μμμ λ§μ§λ§ μμΉλ‘ μ΄λν©λλ€. μμμ λ§μ§λ§ μμΉλ λμμμ κΈΈμ΄μ κ°μ΅λλ€.
- μ€νλ 건λλ°κΈ°: νμ¬ μ¬μ μμΉκ° μ€νλ ꡬκ°(
op_start
≤ νμ¬ μ¬μ μμΉ ≤op_end
)μΈ κ²½μ° μλμΌλ‘ μ€νλμ΄ λλλ μμΉλ‘ μ΄λν©λλ€.
λμμμ κΈΈμ΄λ₯Ό λνλ΄λ λ¬Έμμ΄ video_len
, κΈ°λ₯μ΄ μνλκΈ° μ§μ μ μ¬μμμΉλ₯Ό λνλ΄λ λ¬Έμμ΄ pos
, μ€νλ μμ μκ°μ λνλ΄λ λ¬Έμμ΄ op_start
, μ€νλμ΄ λλλ μκ°μ λνλ΄λ λ¬Έμμ΄ op_end
, μ¬μ©μμ μ
λ ₯μ λνλ΄λ 1μ°¨μ λ¬Έμμ΄ λ°°μ΄ commands
κ° λ§€κ°λ³μλ‘ μ£Όμ΄μ§λλ€. μ΄λ μ¬μ©μμ μ
λ ₯μ΄ λͺ¨λ λλ ν λμμμ μμΉλ₯Ό "mm
:ss
" νμμΌλ‘ return νλλ‘ solution ν¨μλ₯Ό μμ±ν΄ μ£ΌμΈμ.
μ ν μ¬ν
video_len
μ κΈΈμ΄ =pos
μ κΈΈμ΄ =op_start
μ κΈΈμ΄ =op_end
μ κΈΈμ΄ = 5video_len
,pos
,op_start
,op_end
λ "mm
:ss
" νμμΌλ‘mm
λΆss
μ΄λ₯Ό λνλ λλ€.- 0 ≤
mm
≤ 59 - 0 ≤
ss
≤ 59 - λΆ, μ΄κ° ν μλ¦¬μΌ κ²½μ° 0μ λΆμ¬ λ μλ¦¬λ‘ λνλ λλ€.
- λΉλμ€μ νμ¬ μμΉ νΉμ μ€νλμ΄ λλλ μκ°μ΄ λμμμ λ²μ λ°μΈ κ²½μ°λ μ£Όμ΄μ§μ§ μμ΅λλ€.
- μ€νλμ΄ μμνλ μκ°μ νμ μ€νλμ΄ λλλ μκ°λ³΄λ€ μ μ λλ€.
- 1 ≤
commands
μ κΈΈμ΄ ≤ 100commands
μ μμλ "prev" νΉμ "next"μ λλ€.- "prev"λ 10μ΄ μ μΌλ‘ μ΄λνλ λͺ λ Ήμ λλ€.
- "next"λ 10μ΄ νλ‘ μ΄λνλ λͺ λ Ήμ λλ€.
κΈ°λ‘νκΈ°
π‘ μ΄λκΉμ§ μκ°ν΄λ΄€λμ§ λ¨κ³μ μΌλ‘ κΈ°λ‘ν΄λ΄ λλ€.
μ΄λ€ μκ³ λ¦¬μ¦μ μ μ©νλ € νλμ?
μμ. mm:ss
λ₯Ό μ΄λ‘ λ³ννμ¬ κ³μ°νλ € ν¨.
μ μ© κ·Όκ±°λ 무μμΈκ°μ?
κ·Έκ² λ λΉ λ¦
νμ΄
νμ΄ μκ°
μμ μκ° | μ’ λ£ μκ° | μ΄ μμ μκ° |
---|---|---|
13:27 | 14:11 | 44λΆ |
λ¬Έμ λΆμ
μ μ½ μ¬ν νμ & ν μ€νΈ μΌμ΄μ€ μμ±
video_len
μ κΈΈμ΄ =pos
μ κΈΈμ΄ =op_start
μ κΈΈμ΄ =op_end
μ κΈΈμ΄ = 5video_len
,pos
,op_start
,op_end
λ "mm
:ss
" νμμΌλ‘mm
λΆss
μ΄λ₯Ό λνλ λλ€.- 0 ≤
mm
≤ 59 - 0 ≤
ss
≤ 59 - λΆ, μ΄κ° ν μλ¦¬μΌ κ²½μ° 0μ λΆμ¬ λ μλ¦¬λ‘ λνλ λλ€.
- λΉλμ€μ νμ¬ μμΉ νΉμ μ€νλμ΄ λλλ μκ°μ΄ λμμμ λ²μ λ°μΈ κ²½μ°λ μ£Όμ΄μ§μ§ μμ΅λλ€.
- μ€νλμ΄ μμνλ μκ°μ νμ μ€νλμ΄ λλλ μκ°λ³΄λ€ μ μ λλ€.
- 1 ≤
commands
μ κΈΈμ΄ ≤ 100commands
μ μμλ "prev" νΉμ "next"μ λλ€.- "prev"λ 10μ΄ μ μΌλ‘ μ΄λνλ λͺ λ Ήμ λλ€.
- "next"λ 10μ΄ νλ‘ μ΄λνλ λͺ λ Ήμ λλ€.
μ λ ₯κ° λΆμ
π‘ μ λ ₯κ°μ λΆμνλ©΄ λ¬Έμ μμ μꡬνλ μκ³ λ¦¬μ¦μ μκ° λ³΅μ‘λλ₯Ό κ°μ μ μΌλ‘ νμ ν μ μμ΅λλ€.
video_len | pos | op_start | op_end | commands | result |
---|---|---|---|---|---|
"34:33" | "13:00" | "00:55" | "02:55" | ["next", "prev"] | "13:00" |
"10:55" | "00:05" | "00:15" | "06:55" | ["prev", "next", "next"] | "06:55" |
"07:22" | "04:05" | "00:15" | "04:07" | ["next"] | "04:17" |
μ μΆλ ₯ μ #1
- μμ μμΉ 13λΆ 0μ΄μμ 10μ΄ νλ‘ μ΄λνλ©΄ 13λΆ 10μ΄μ λλ€.
- 13λΆ 10μ΄μμ 10μ΄ μ μΌλ‘ μ΄λνλ©΄ 13λΆ 0μ΄μ λλ€.
- λ°λΌμ "13:00"μ return νλ©΄ λ©λλ€.
μ μΆλ ₯ μ #2
- μμ μμΉ 0λΆ 5μ΄μμ 10μ΄ μ μΌλ‘ μ΄λν©λλ€. νμ¬ μμΉκ° 10μ΄ λ―Έλ§μ΄κΈ° λλ¬Έμ 0λΆ 0μ΄λ‘ μ΄λν©λλ€.
- 0λΆ 0μ΄μμ 10μ΄ νλ‘ μ΄λνλ©΄ 0λΆ 10μ΄μ λλ€.
- 0λΆ 10μ΄μμ 10μ΄ νλ‘ μ΄λνλ©΄ 0λΆ 20μ΄μ λλ€. 0λΆ 20μ΄λ μ€νλ ꡬκ°μ΄κΈ° λλ¬Έμ μ€νλμ΄ λλλ μμΉμΈ 6λΆ 55μ΄λ‘ μ΄λν©λλ€. λ°λΌμ "06:55"λ₯Ό return νλ©΄ λ©λλ€.
μ μΆλ ₯ μ #3
- μμ μμΉ 4λΆ 5μ΄λ μ€νλ ꡬκ°μ΄κΈ° λλ¬Έμ μ€νλμ΄ λλλ μμΉμΈ 4λΆ 7μ΄λ‘ μ΄λν©λλ€. 4λΆ 7μ΄μμ 10μ΄ νλ‘ μ΄λνλ©΄ 4λΆ 17μ΄μ λλ€. λ°λΌμ "04:17"μ return νλ©΄ λ©λλ€.
μμ¬ μ½λ μμ±
π‘ μμ¬ μ½λλ λμ μ€μ¬μΌλ‘ μμ±νλ κ²μ΄ μ€μν©λλ€.
π‘ μμ¬ μ½λλ λ¬Έμ ν΄κ²° μμλ‘ μμ±ν©λλ€.
π‘ μμ¬ μ½λλ₯Ό μΆ©λΆν ν μ€νΈν΄λ΄ λλ€.
solution(video_len, pos, op_start, op_end, commands) {
// 1. (string) mm:ss -> (int) mm * 60 + ss λ³κ²½
for (String command : commands) {
// 2. μ€νλ ꡬκ°μ μνλμ§ νμ
νμ
// 3. prev μΌ λ 0λΆ 0μ΄ νμΈ
// 4. next μΌ λ λμμ κΈΈμ΄ μ΄κ³Όνλμ§ νμΈ
}
// 5. (int) mm * 60 + ss -> pos: (string) time / 60 + ":" + (string) time % ss λ³κ²½
}
ꡬν
import java.util.HashMap;
class Solution {
public String solution(String video_len, String pos, String op_start, String op_end, String[] commands) {
// 1. (string) mm:ss -> (int) mm * 60 + ss λ³κ²½
int total = convertMmSsTo60s(video_len);
int current = convertMmSsTo60s(pos);
int start = convertMmSsTo60s(op_start);
int end = convertMmSsTo60s(op_end);
// 2. 컀맨λ맡 μμ±
HashMap<String, Integer> commandsMap = new HashMap<>();
commandsMap.put("next", 10);
commandsMap.put("prev", -10);
for (String command : commands) {
// 3. 컀맨λλ§λ€ μ€νλ ꡬκ°μ μνλμ§ νμ
νμ
if (start <= current && current < end) {
current = end;
}
current = Math.min(total, Math.max(0, current + commandsMap.get(command)));
}
// 4. κ΅¬κ° μ΅μ’
νμΈ
current = start <= current && current < end ? end : current;
// 5. (int) seconds -> (string) mm:ss λ³ν
return convert60sToMmSs(current);
}
// (string) mm:ss -> (int) seconds λ³ν
public int convertMmSsTo60s(String mmSs) {
String[] mmAndSs = mmSs.split(":");
return Integer.parseInt(mmAndSs[0]) * 60 + Integer.parseInt(mmAndSs[1]);
}
// (int) seconds -> (string) mm:ss λ³ν
public String convert60sToMmSs(int seconds) {
String mm = padLeft(2, seconds / 60);
String ss = padLeft(2, seconds % 60);
return mm + ":" + ss;
}
public String padLeft(int n, int i) {
return String.format("%0" + n + "d", i);
}
}
'Algorithm > ν μ½ν μ½1.5(2025.01)' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[ν μ½ν μ½1.5 1-06] λλ€μ κ·μΉ (0) | 2025.01.12 |
---|---|
[ν μ½ν μ½1.5 1-05] λ²μ€ (0) | 2025.01.12 |
[ν μ½ν μ½1.5 1-04] μ λλκΈ° (0) | 2025.01.12 |
[ν μ½ν μ½1.5 1-03] κ°λ ν©μΉκΈ° (0) | 2025.01.12 |
[ν μ½ν μ½1.5 1-02] λ¬Έμ μΆλ ₯ (0) | 2025.01.12 |