프로그래머스 : n보다 커질 때까지 더하기

Digeut·2024년 5월 23일
0

프로그래머스

목록 보기
165/170

❔문제설명

🤔아이디어

반복문을 돌리면서 n보다 커지면 탈출시키면되지않을까?

💡코드풀이

class Solution {
    public int solution(int[] numbers, int n) {
        int answer = 0;
        for(int i = 0 ; i < numbers.length ; i++){
            answer += numbers[i];
            if(answer > n){
                break;
            }else{
                continue;
            }
        }
        return answer;
    }
}
profile
백엔드 개발자 지망생

0개의 댓글