프로그래머스_C#/Level_1
[프로그래머스 C#] K번째수
최애뎡
2021. 9. 7. 00:10
728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/42748
코딩테스트 연습 - K번째수
[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]
programmers.co.kr
using System;
using System.Linq;
public class Solution {
public int[] solution(int[] array, int[,] commands) {
int[] answer = new int[commands.GetLength(0)];
for(int i = -1; ++i < answer.Length;)
{
int start = commands[i, 0] - 1;
int end = commands[i, 1] - commands[i, 0] + 1;
int choice = commands[i, 2] - 1;
answer[i] = array.ToList().GetRange(start, end).OrderBy(x => x).ToArray()[choice];
}
return answer;
}
}
Linq 사용해서 편하게
반응형