Simple 5 Lines, 7ms JAVA

  • 5

    Simple 5-liner using sort. You could implement your own sort and break when you find a duplicate making it faster.

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

  • 0

    so your answer costs O(nlogn)?

  • 0

    I submit the same code ,but I was told Time Limit Exceeded.

Log in to reply

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