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

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


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

查看所有标签

猜你喜欢:

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

Beginning XSLT 2.0

Beginning XSLT 2.0

Jeni Tennison / Apress / 2005-07-22 / USD 49.99

This is an updated revision of Tennison's "Beginning XSLT", updated for the new revision of the XSLT standard. XSLT is a technology used to transform an XML document with one structure into another ......一起来看看 《Beginning XSLT 2.0》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具