MapleStory Finger Point

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

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - java n๋ณด๋‹ค ์ปค์งˆ ๋•Œ๊นŒ์ง€ ๋”ํ•˜๊ธฐ

HYEJU01 2024. 5. 2. 09:50

๐Ÿ’ก ์•ž์—์„œ ํ•˜๋‚˜์”ฉ ๋”ํ•˜๋‹ค๊ฐ€ n ๋ณด๋‹ค ์ปค์ง€๋Š” ๊ฐ’์ด ์ƒ๊ธฐ๋Š” ์ˆœ๊ฐ„๊นŒ์ง€ ๋”ํ–ˆ๋˜ ํ•ฉ์„ ๋ฆฌํ„ดํ•˜๋ผ

 

class Solution {
    public int solution(int[] numbers, int n) {
        int answer = 0;
        
        
         for (int i = 0 ; i < numbers.length; i++){
             if (answer <= n){
                answer += numbers[i];   
             }
         }
        
        return answer;
    }
}