Java Solution; O(n log n) running time, O(1) memory, 5ms.


  • 0
    S
    public class Solution {
      public boolean containsDuplicate(int[] nums) {
        if (nums == null || nums.length < 2) return false;
        Arrays.sort(nums);
        int n = nums[0];
        for (int i = 1; i < nums.length; i++) {
          final int m = nums[i];
          if (n == m) return true;
          n = m;
        }
        return false;
      }
    }
    

Log in to reply
 

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