Tuesday, May 24, 2022

[LeetCode] 268. Missing Number

       

"踏上LeetCode解題之路,順手紀錄一下PHP練功的過程囉。這是第二十篇~~"


Missing Number - LeetCode

思考過程

待補上


結果

class Solution {

    /**
     * @param Integer[] $nums
     * @return Integer
     */
    function missingNumber($nums) {
        
        $count = count($nums);
        
        $i = 0;
        
        while($i <= $count) {
            $key = array_search($i, $nums);
            
            if ($key == ''){
                return $i;                
            } 
            
            $i++;
        }
    }
}

參考資料

array_search

Contact Form

Name

Email *

Message *