Created
April 27, 2020 16:05
-
-
Save DongguemYoo/9c569876a46711d9cb33460a6205dc79 to your computer and use it in GitHub Desktop.
코딩테스트 연습 >정렬>k번째수
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//다차원 배열 길이 구하는방법:commands.GetLength(0) 을 몰라서 해맷음 | |
using System; | |
public class Solution { | |
public int[] solution(int[] array, int[,] commands) { | |
int[] answer = new int[commands.GetLength(0)]; | |
int[] reArray = new int[] { 0, }; | |
for (int i = 0; i < commands.GetLength(0); i++) | |
{ | |
reArray = new int[commands[i, 1] - commands[i, 0] + 1]; | |
for (int j = 0; j < commands[i, 1] - commands[i, 0] + 1; j++) | |
{ | |
reArray[j] = array[(commands[i, 0] + j - 1)]; | |
} | |
Array.Sort(reArray); | |
answer[i] = reArray[commands[i, 2] - 1]; | |
} | |
return answer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment