首页 > 其他 > 详细

217. 存在重复元素

时间:2019-05-20 10:24:47      阅读:119      评论:0      收藏:0      [点我收藏+]

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

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

示例 1:

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

示例 2:

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

示例 3:

输入: [1,1,1,3,3,4,3,2,4,2]
输出: true
class Solution {
    public boolean containsDuplicate(int[] nums) {
        return Arrays.stream(nums).boxed().collect(Collectors.toMap(x -> x, x -> 1, 
            Integer::sum)).values().stream().anyMatch(x -> x > 1);
    }
}

  

217. 存在重复元素

原文:https://www.cnblogs.com/Stefan-24-Machine/p/10892071.html

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