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);
    }
}

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


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

查看所有标签

猜你喜欢:

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

Professional JavaScript for Web Developers

Professional JavaScript for Web Developers

Nicholas C. Zakas / Wrox / 2009-1-14 / USD 49.99

This eagerly anticipated update to the breakout book on JavaScript offers you an in-depth look at the numerous advances to the techniques and technology of the JavaScript language. You'll see why Java......一起来看看 《Professional JavaScript for Web Developers》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具