120ms JavaScript solution


  • 0
    E

    Here's my solution using JavaScript that runs in 120ms

    /**
     * @param {number[]} nums
     * @return {boolean}
     */
    var containsDuplicate = function(nums) {
        nums.sort(function  (a, b) {
          return a - b;
        });
        while (nums.length > 0) {
          var cur = nums.shift();
        if(nums[0] === cur) return true;
        }
        return false;
    };

Log in to reply
 

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