class Solution {
\
/**
* @param ListNode $l1
* @param ListNode $l2
* @return ListNode
*/
function addTwoNumbers($l1, $l2) {
$result = '';
\
$count1 = count($l1);
$count2 = count($l2);
$next_num = 0;
\
do{
\
$num1 = isset($l1[$count1 - 1]) ? $l1[$count1 - 1] : 0;
$num2 = isset($l2[$count2 - 1]) ? $l2[$count2 - 1] : 0;
\
$temp = $num1 + $num2 + $next_num;
\
if($temp > 9){
$result .= $temp%10;
$next_num = 1;
}else{
$result .= $temp;
$next_num = 0;
}
\
$count1--;
$count2--;
\
}while($count1 >=0 || $count2 >= 0 || $next_num);
}
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結