问题1 找出数组中重复的数字。
    在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。
    利用Set 集合 是不可重复的是特点
    建立一个HashSet 要是集合中 有就直接返回 当前num
    Set.contains()
    利用hashmap 遍历 数组 将数组的元素做KEY出现次数做Value进行 存储 map.put(nums[i],getOrDefault(nums[i],0)+1)
    最后遍历输出Value大于2的数
    示例 1:

    输入:
    [2, 3, 1, 0, 2, 5, 3]
    输出:2 或 3

    1. class Solution {
    2. public int findRepeatNumber(int[] nums) {
    3. Set<Integer> dic = new HashSet<>();
    4. for(int num : nums) {
    5. if(dic.contains(num)) return num;
    6. dic.add(num);
    7. }
    8. return -1;
    9. }
    10. }

    问题2
    统计一个数字在排序数组中出现的次数。
    双指针 、Hashmap都能做
    示例 1:
    输入: nums = [5,7,7,8,8,10], target = 8 输出: 2

    1. class Solution {
    2. public int search(int[] nums, int target) {
    3. // Map<Integer,Integer> map = new HashMap<>();
    4. int a =0;
    5. int l=0;
    6. int r =nums.length-1;
    7. while(l<r){
    8. if(nums[r] == target)
    9. {a++;}
    10. if(nums[l] == target)
    11. {a++;}
    12. l++;
    13. r--;
    14. }
    15. if(r==l){ if(nums[r] == target)
    16. {a++;}}
    17. return a;
    18. }
    19. }

    问题3:
    一个长度为n-1的递增排序数组中的所有数字都是唯一的,并且每个数字都在范围0~n-1之内。在范围0~n-1内的n个数字中有且只有一个数字不在该数组中,请找出这个数字。
    双指针,普通做法
    示例 1:

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

    1. class Solution {
    2. public int missingNumber(int[] nums) {
    3. for(int i=0 ; i< nums.length;i++){
    4. if(i!=nums[i])
    5. return i;
    6. }
    7. return nums.length;
    8. }
    9. }