[프로그래머스/Java] Lv.0 정수 찾기

febCho·2024년 3월 20일
0

코딩테스트

목록 보기
113/253
post-thumbnail

문제

정수 리스트 num_list와 찾으려는 정수 n이 주어질 때, num_list안에 n이 있으면 1을 없으면 0을 return하도록 solution 함수를 완성해주세요.

- 제한사항

  • 3 ≤ num_list의 길이 ≤ 100
  • 1 ≤ num_list의 원소 ≤ 100
  • 1 ≤ n ≤ 100

풀이

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

결과

profile
Done is better than perfect.

0개의 댓글