Java sort solution


  • -3
    F
    public class Solution {
        public boolean containsDuplicate(int[] nums) {
            boolean dups = false;
            if (nums.length >= 1) {
                Arrays.sort(nums);
                for (int i = 1; i < nums.length; i++) {
                    if (nums[i-1] == nums[i]) {
                        dups = true;
                        break;
                    }
                }    
            }
            return dups;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.