ONE PASS.

int[][] map = new int[5][9]; int ans = 0; for (int num : nums) { int r = num / 100, c = num % 100 / 10, v = num % 10; map[r][c] = v; if (r > 1) { int p = map[r - 1][(c + 1) / 2]; map[r][c] += Math.abs(p); if (p > 0) { ans -= p; map[r - 1][(c + 1) / 2] = -p; } } ans += map[r][c]; } return ans;Path Sum IV