217. Contains Duplicate

幼儿园都会做

    //0. O(n2)brute force
    //1. sort
    //2. map/set
    public boolean containsDuplicate(int[] nums) {
        Arrays.sort(nums);
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == nums[i - 1]) return true;
        }
        return false;
    }

你可能感兴趣的:(217. Contains Duplicate)