Notice
Recent Posts
Recent Comments
Today
Total
01-10 22:06
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[์ •๋ ฌ] K ๋ฒˆ์งธ์ˆ˜ (JAVA) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[์ •๋ ฌ] K ๋ฒˆ์งธ์ˆ˜ (JAVA)

WonderJay 2022. 9. 2. 14:51
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://school.programmers.co.kr/learn/courses/30/lessons/42748?language=java 

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

import java.io.IOException;
import java.util.Arrays;

class Solution{
    public int[] solution(int[] array, int[][] commands) throws IOException {
        int[] answer = new int[commands.length];
        int t = commands.length;

        for(int i = 0 ; i < t ; i++){
            int s = commands[i][0];
            int e = commands[i][1];
            int k = commands[i][2];

            int[] temp = Arrays.copyOfRange(array, s-1, e);
            Arrays.sort(temp);
            answer[i] = temp[k-1];
        }

        return answer;
    }
}

 

728x90
๋ฐ˜์‘ํ˜•
LIST
Comments