MapleStory Finger Point

๐Ÿƒ‍โ™€๏ธprogrammers/Java

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - java ์ˆ˜์—ด๊ณผ ๊ตฌ๊ฐ„ ์ฟผ๋ฆฌ 1

HYEJU01 2024. 5. 2. 10:02

๐Ÿ’กqueries ์˜ s ~ e ์˜ ๋ชจ๋“  arr[i] ์— ๋Œ€์‘ํ•˜๋Š” ๊ฐ’์— +1 ์”ฉ ๋”ํ•œ๋‹ค.

 

queries ์— ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ•์ด  2์ฐจ์› ๋ฐฐ์—ด์ด๋ผ ๊นŒ๋‹ค๋กญ๋‹ค!!

for ๋ฌธ 1์ฐจ์— queries ์ ‘๊ทผ๊ฐ’์„ ์ง€์ •ํ•ด์ฃผ๊ณ 

for๋ฌธ 2์ฐจ์—๋Š” ์‹์„ ๋Œ๋ ค์ฃผ๋ฉด ์‰ฝ๊ฒŒ ํ•ด๊ฒฐ๋œ๋‹ค.

class Solution {
    public int[] solution(int[] arr, int[][] queries) {
        
        for (int i =0 ; i < queries.length; i++){
            int s = queries[i][0];
            int e = queries[i][1];
            
            for (int j = s; j<=e; j++){
                arr[j]+=1 ;
            }
            
        }
        return arr;
    }
}