브루트포스로 풀었다. 현재 숫자
와 입력리스트의 인덱스
를 따로 저장해두고, 현재 숫자를 하나씩 쪼개서 for문을 돌면서 입력리스트[인덱스]
와 같은 게 있다면 인덱스를 하나씩 올리는 식으로 구현했다.
예제 입력 2를 예로 들어 그림을 그려보면 아래와 같다.
const fs = require("fs");
const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt";
const arr = fs.readFileSync(filePath).toString().trim().split("");
let now = 0; // 현재 숫자
let idx = 0; // 입력리스트 index
while (idx < arr.length) {
now++;
const nowstr = now.toString(); // Number을 String으로 바꾸고
for (let i = 0; i < nowstr.length; i++) {
if (nowstr[i] === arr[idx]) { // 비교. 일치하면
idx++; // 입력 index + 1
}
}
}
console.log(now);