You are viewing a single comment's thread. Return to all comments →
PHP:
function diagonalDifference($arr) { $firstArray = []; $secondArray = []; $i = 0; while ($i < count($arr)) { $firstArray[] = $arr[$i][$i]; $i++; } $i = 0; $j = count($arr) - 1; while ($i < count($arr)) { $secondArray[] = $arr[$i][$j]; $i++; $j--; } $first = array_sum($firstArray); $second = array_sum($secondArray); return $first > $second ? $first - $second : $second - $first; }
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
PHP: