Skip to content

Instantly share code, notes, and snippets.

@DongguemYoo
Created April 27, 2020 16:05
Show Gist options
  • Save DongguemYoo/9c569876a46711d9cb33460a6205dc79 to your computer and use it in GitHub Desktop.
Save DongguemYoo/9c569876a46711d9cb33460a6205dc79 to your computer and use it in GitHub Desktop.
코딩테스트 연습 >정렬>k번째수
//다차원 배열 길이 구하는방법: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