Day7. Contains Duplicate(217)

问题描述
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
思路:刚开始就用了双层for循环,超时了

/**
 * @param {number[]} nums
 * @return {boolean}
 */
var containsDuplicate = function(nums) {
    nums.sort();
    for(var i = 0; i < nums.length-1; i++){
        if(nums[i] == nums[i+1]){
            return true;
        }
    }
    return false;
};
    原文作者:前端伊始
    原文地址: https://www.jianshu.com/p/6d74a8eb43aa
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞