Leetcode PHP题解--D79 448. Find All Numbers Disappeared in an Array

栏目: PHP · 发布时间: 6年前

内容简介:给定一个1到n的数组,返回其中缺失的数字。用range得出1到n的数字,再用array_diff和给定的数组计算差集。

D79 448. Find All Numbers Disappeared in an Array

题目链接

448. Find All Numbers Disappeared in an Array

题目分析

给定一个1到n的数组,返回其中缺失的数字。

思路

用range得出1到n的数字,再用array_diff和给定的数组计算差集。

最终代码

<?php
class Solution {

    /**
     * @param Integer[] $nums
     * @return Integer[]
     */
    function findDisappearedNumbers($nums) {
        if(!$nums){
            return [];
        }
        return array_diff(range(1,count($nums)),$nums);
    }
}

若觉得本文章对你有用,欢迎用 爱发电 资助。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Cypherpunks

Cypherpunks

Julian Assange、Jacob Appelbaum、Andy Müller-Maguhn、Jérémie Zimmermann / OR Books / 2012-11 / GBP 8.99

Cypherpunks are activists who advocate the widespread use of strong cryptography (writing in code) as a route to progressive change. Julian Assange, the editor-in-chief of and visionary behind WikiLea......一起来看看 《Cypherpunks》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具