๊ด€๋ฆฌ ๋ฉ”๋‰ด

Daehyunii's Dev-blog

์ขŒํ‘œ ์ •๋ ฌ ๋ณธ๋ฌธ

๋ฌธ์ œ(์ถœ์ฒ˜ : ์ธํ”„๋Ÿฐ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œํ’€์ด ๊ฐ•์˜, ์ •๋ณด์˜ฌ๋ฆผํ”ผ์•„๋“œ)

N๊ฐœ์˜ ํ‰๋ฉด์ƒ์˜ ์ขŒํ‘œ(x, y)๊ฐ€ ์ฃผ์–ด์ง€๋ฉด ๋ชจ๋“  ์ขŒํ‘œ๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜ ์„ธ์š”. ์ •๋ ฌ๊ธฐ์ค€์€ ๋จผ์ € x๊ฐ’์˜ ์˜ํ•ด์„œ ์ •๋ ฌํ•˜๊ณ , x๊ฐ’์ด ๊ฐ™์„ ๊ฒฝ์šฐ y๊ฐ’์— ์˜ํ•ด ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค.

โ–ฃ ์ž…๋ ฅ์„ค๋ช…
์ฒซ์งธ ์ค„์— ์ขŒํ‘œ์˜ ๊ฐœ์ˆ˜์ธ N(3<=N<=100,000)์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.
๋‘ ๋ฒˆ์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ขŒํ‘œ๊ฐ€ x, y ์ˆœ์œผ๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. x, y๊ฐ’์€ ์–‘์ˆ˜๋งŒ ์ž…๋ ฅ๋ฉ๋‹ˆ๋‹ค.

 

โ–ฃ ์ถœ๋ ฅ์„ค๋ช…
N๊ฐœ์˜ ์ขŒํ‘œ๋ฅผ ์ •๋ ฌํ•˜์—ฌ ์ถœ๋ ฅํ•˜์„ธ์š”.

 

โ–ฃ ์ž…๋ ฅ์˜ˆ์ œ 1

5
27
13

12 25 36

 

โ–ฃ ์ถœ๋ ฅ์˜ˆ์ œ 1

12
13
25

27 36

 

Tip

 

๋ฌธ์ œํ’€์ด

//๊ฐ•์˜ ๋“ฃ๊ณ  ๋‚ด๊ฐ€ ๋‹ค์‹œ ์ž‘์„ฑํ•œ ๋‹ต
function solution(arr){
    let answer = arr;

    arr.sort((a,b) => {
        if(a[0]===b[0]) return a[1]-b[1];
        else return a[0]-b[0];
    });

    return answer;
}

let arr4=[[2, 7], [1, 3], [1, 2], [2, 5], [3, 6]];
console.log(solution(arr4));