首页 > 编程语言 > 详细

[LeetCode][JavaScript]Contains Duplicate

时间:2015-05-26 01:35:37      阅读:436      评论:0      收藏:0      [点我收藏+]

Contains Duplicate

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.

https://leetcode.com/problems/contains-duplicate/

 

 


 

 

水一题调节心情。

 1 /**
 2  * @param {number[]} nums
 3  * @return {boolean}
 4  */
 5 var containsDuplicate = function(nums) {
 6     if(nums.length === 0){
 7         return false;
 8     }
 9     var map = {};
10     for(var i in nums){
11         if(!map[nums[i]]){
12             map[nums[i]] = 1;
13         }else{
14             map[nums[i]]++;
15         }
16     }
17     for(i in map){
18         if(map[i] >= 2){
19             return true;
20         }
21     }
22     return false;
23 };

 

 

 
 

[LeetCode][JavaScript]Contains Duplicate

原文:http://www.cnblogs.com/Liok3187/p/4529488.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!