数组 - 找出重复项

in Algorithm with 0 comment

从数组中找出重复项

Description

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.

Programmer

var containsDuplicate = function(nums) {
    
    for(let i = 0; i < nums.length; i++) {
        for (let j = i+1; j < nums.length; j++) {
            if(nums[i] == nums[j]) {
                return true;
            }
        }
    }
    
    return false;
};

Idea: