From the code I guess that the example is missing a first line that's supposed to contain the number of lines of the triangle.
Regarding the "question" : it's too vague, which biggest numbers ?
I understand what the solution does, and its not
the sum of the biggest numbers
It computes the biggest sum along a "path" from top to bottom.
What I call a path is :
- start from the top value
- choose a value between the one that's right under or the one that's right under and to the right
- for each value you choose, repeat this process
- stop when you've reached the bottom of this triangle
The succession of values you've chosen forms a "path" from top to bottom in the triangle.
I think that you should use a different approach. As you have done, initialize the triangle to a 2D array, but instead of going from the top down, go from the bottom up:
2
3 4
5 4 9
9 8 7 5
Start with the second to bottom row, element one, 5. Compare the two paths below it, (8 and 9). Since 9 is greater add 9 to five and store the result in place of 5.
Now it reads:
1
3 4 14 4 9
9 8 7 5
Repeat the process for all elements in the row, and then move up a row. Then the greatest path sum will be stored in the top of the array.