ARTS打卡第三周

Algorithm

题目描述

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.

Example 1:

Input: [1,2,3,1]
Output: true

Example 2:

Input: [1,2,3,4]
Output: false

Example 3:

Input: [1,1,1,3,3,4,3,2,4,2]
Output: true

分析:这个题目就是,如果数组有重复项,就返回true,没有就返回false。
刚开始的时候自己用,两个循环来做,可以测试通过,但就是提交出错。
之后又参考网上的内容,利用HashSet中的元素不能重复这一特性来做。把数组中的元素放入Set集合中,如果数组的长度和Set的长度相同,
说明没有重复元素,若是Set的长度小于数组的长度,说明存在重复元素。
class Solution {
    public boolean containsDuplicate(int[] nums) {
        if(nums.length == 1){
            return false;
        }
        
       HashSet set = new HashSet<Integer>();
        for(int i = 0; i < nums.length; i++){
            set.add(nums[i]);
        }
        if(set.size() == nums.length){
            return false;
        }else{
            return true;
        }
    }
}

 Review

  https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-new-framework

  上面这篇文章是,spring5的介绍。只看了1.1节。主要讲述了Spring MVC  和Spring WebFlux 的区别和联系。Spring MVC 支持的io是阻塞式的,而Spring WebFlux支持的io是非阻塞式的,对于多线程有较好的应用。

Tip

在java中 >>>  是一个 对象的二进制数往右移三位 ,左边空出来的位数补0。 >>是算术右移,空出来的位置补符号位。

比如一个有符号位的8位二进制数10101010,[]是添加的数字

逻辑右移一位:[0]1010101
逻辑右移两位:[00]101010

算术右移一位:[1]1010101
算术右移两位:[11]101010

参考文章:https://blog.csdn.net/zzti_erlie/article/details/80204053

Share: 

分享一篇,怎么处理好在家族工作和长辈关系的文章吧:感觉文章说的挺有智慧的。

https://mp.weixin.qq.com/s/KOVXSbsQW_JFnlHwm0fNFg

 

猜你喜欢

转载自www.cnblogs.com/prader6/p/10742509.html