[프로그래머스] 순열검사

2020. 4. 7. 15:03프로그래머스/LEVEL 2

import java.util.*;

class Solution {
    public boolean solution(int[] arr) {
        boolean answer = true;

        Set<Integer> s = new HashSet<>();

        for(int i=0; i<arr.length; i++){
            if(arr[i]<=arr.length&&!s.contains(arr[i])){
                s.add(arr[i]);
            }else{
                return false;
            }
        }
        
        if(s.size()!=arr.length){
            return false;
        }
        return answer;
    }
}