在LeetCode上面的一道算法题

两数之和

查看详情

class Solution {

    /**
     * @param Integer[] $nums
     * @param Integer $target
     * @return Integer[]
     */
function twoSum($nums, $target) {
    $i = 0;
    while($i < count($nums))
    {
        for($j = ($i+1); $j < count($nums); $j++){
            if(($nums[$i]+$nums[$j]) == $target){
                return array($i, $j);
            }
        }
        $i++;
    }
}
}