My java method using sort();


  • 0
    X
    public class Solution {
        public boolean containsDuplicate(int[] nums) {
            int length = nums.length;
            // boolean result = false;
            if(length<=1){
                return false;
            }
            Arrays.sort(nums);
            
            for(int i=0; i<length-1; i++){
                if(nums[i] == nums[i+1]){
                    return true;
                    
                }
            }
            return false;
        }
    }

Log in to reply
 

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