Java solution with array sorting and backward loop, beats 97.24% of java submissions


  • 0
    S
    public class Solution {
        public boolean containsDuplicate(int[] nums) {
            if(nums == null || nums.length ==0){
            	return false;
            }
    		
    		Arrays.sort(nums);
    		int p = nums.length-1;
    		while(p>0){
    			if(nums[p--] == nums[p]){
    				return true;
    			}
    		}
    		
    		return false;
        }
    }
    

Log in to reply
 

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