[leetcode][PHP实现]Contains Duplicate

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
class Solution 
{
    public function containsDuplicate($nums) 
    {
        $hashTable = array();
        foreach ($nums as $num)
        {
            if (!array_key_exists($num,$hashTable))
            {
                $hashTable[$num] = 1;
            }
            else
            {
                return false;
            }
        }
        return true;
    }
}
$solution = new Solution();
echo $solution->containsDuplicate(array(2,1,3,4,5,6,7,9));
?>
Licensed under CC BY-NC-SA 4.0