[algorithm] 정수 찾기

인철·2024년 2월 26일
0

algorithm

목록 보기
75/91

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

class Solution {
    public int solution(int[] num_list, int n) {
        int answer = 0; // answer을 0으로 초기화
        for(int i = 0; i < num_list.length; i++){
            if(num_list[i] == n){ // num_list[i] 구하기
                answer = 1; // 맞으면 answer = 1;
            }
        }
        return answer; // 아니면 0
    }
}
profile
같은글이있어도양해부탁드려요(킁킁)

0개의 댓글