O(n) Easy Method


  • -1
    L

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


  • 1
    F

    Hi liuyu666, to format your code in a standard format.
    Just put your code between two ```

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

  • 0
    L

    @FF_Ti Thank you very much!


Log in to reply
 

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