0
点赞
收藏
分享

微信扫一扫

数组简单 LeetCode217. 存在重复元素

松鼠树屋 2022-03-17 阅读 55

217. 存在重复元素

描述

给你一个整数数组 nums 。如果任一值在数组中出现 至少两次 ,返回 true ;如果数组中每个元素互不相同,返回 false 。

分析

stream是util包下面的接口
stream的方法:
long count() 返回此流中元素的数量。
Stream distinct() 返回由此流的不同元素(根据 Object.equals(Object) )组成的流。

class Solution {
    public boolean containsDuplicate(int[] nums) {
        return (int)Arrays.stream(nums).distinct().count() != nums.length;
    }
}
举报

相关推荐

0 条评论