题解 | #数组里面没有出现过的数字#

数组里面没有出现过的数字

https://www.nowcoder.com/practice/aa2a56603fb94b3395ea23ff89d37628

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param nums int整型一维数组 
     * @return int整型一维数组
     */
    public int[] findDisappearedNumbers (int[] nums) {
        // write code here
        int[] arr = new int[nums.length];
        for (int i = 0; i < nums.length; i++){
            arr[nums[i]-1]++;
        }
        int count = 0;
        for (int i = 0; i < nums.length; i++){
            if (arr[i] == 0){
                count++;
            }
        }
        int[] ret = new int[count];
        int k = 0;
        for (int i = 0; i < nums.length; i++){
            if (arr[i] == 0){
                ret[k++] = i+1;
            }
        }

        return ret;
    }
}

全部评论

相关推荐

10-13 16:58
门头沟学院 Java
面了100年面试不知...:一周七天,一天去一家上班😍😍😍
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务