Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

存在重复的元素 #12

Open
Aras-ax opened this issue Mar 9, 2019 · 0 comments
Open

存在重复的元素 #12

Aras-ax opened this issue Mar 9, 2019 · 0 comments

Comments

@Aras-ax
Copy link
Owner

Aras-ax commented Mar 9, 2019

给定一个整数数组,判定是否存在重复元素。

如果任何值在数组中出现至少两次,函数返回true。如果数组中每个元素都不相同,则返回false。

示例 1

输入:[1, 2, 3, 1]
输出:true

示例 2

输入:[1, 2, 3, 4]
输出:false

解答

function hasRepeat(nums) {
    let hashMap = {};
    return nums.some(item => {
        if (hashMap[item]) {
            return true;
        }
        hashMap[item] = true;
    });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant