美文网首页Leetcode题解-PHP版
Leetcode PHP题解--D114 268. Missin

Leetcode PHP题解--D114 268. Missin

作者: skys215 | 来源:发表于2019-08-09 10:35 被阅读0次

    D114 268. Missing Number

    题目链接

    268. Missing Number

    题目分析

    给定一个从0~n的数组,返回缺少哪一个数字。

    思路

    用array_diff即可。

    最终代码

    <?php
    class Solution {
    
        /**
         * @param Integer[] $nums
         * @return Integer
         */
        function missingNumber($nums) {
            $all = range(0,count($nums));
            $d =  array_diff($all,$nums);
            return current($d);
        }
    }
    

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

    相关文章

      网友评论

        本文标题:Leetcode PHP题解--D114 268. Missin

        本文链接:https://www.haomeiwen.com/subject/pescjctx.html