코딩테스트

20250312

불닭냠냠 2025. 3. 13. 13:13

//숫자 찾기

function solution(num, k) {
  let index = num.toString().indexOf(k.toString());
  return index === -1 ? -1 : index + 1;
}

 

// k번째 수

function solution(array, commands) {
  var answer = [];
  for (let n = 0; n < commands.length; n++) {
    const command = commands[n];
    const i = command[0];
    const j = command[1];
    const k = command[2];
    sliceArray = array.slice(i - 1, j).sort((a, b) => a - b);
    answer.push(sliceArray[k - 1]);
  }
  return answer;
}

'코딩테스트' 카테고리의 다른 글

20250314  (2) 2025.03.15
20250313  (0) 2025.03.14
20250311  (3) 2025.03.11
20250310  (0) 2025.03.10
20250307  (0) 2025.03.10