Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- list
- Filter
- collection
- Generic
- Interface
- class component
- vuex
- union
- Service
- Swift
- enum
- mongoose
- map
- CLASS
- docker
- docker-compose
- ConstraintLayout
- animation
- Kotlin
- 생명주기
- recyclerview
- MINUS
- react native
- ReactNative
- AWS
- LiveData
- elementAt
- function
- lifecycle
- Foreign Key
Archives
- Today
- Total
개발 일기
알고리즘 연습 본문
https://school.programmers.co.kr/learn/courses/30/lessons/154538
function solution(x, y, n) {
if (x === y) return 0;
const dp = {};
dp[x] = 0;
let data = [x];
while (data.length) {
const newData = [];
for (let i = 0; i < data.length; i += 1) {
const condition = [data[i] + n, data[i] * 2, data[i] * 3]
for (let j = 0; j < condition.length; j += 1) {
if(condition[j] > y || dp[condition[j]]) continue;
if(condition[j] === y) return dp[data[i]] + 1
dp[condition[j]] = dp[data[i]] + 1
newData.push(condition[j])
}
}
data = newData
}
return -1;
}
Comments