Suppose you have $N$ balls and the sides of your triangle have $n$ balls. Then the number of balls needed for the triangle is:
$$n + (n-1) + (n-2) + \ldots + 3 + 2 + 1 = \textrm{number of balls in triangle}.$$
Now we have two unknowns, $N$ and $n$, which means we need two equations. For the first triangle 19 balls were not used, so:
$$n + (n-1) + (n-2) + \ldots + 3 + 2 + 1 = N-19.$$
With the triangle sized up we are 5 balls short, so we have:
$$(n+1) + \Big[n + (n-1) + (n-2) + \ldots + 3 + 2 + 1\Big] = N+5.$$
Now we can combine the latter two equations to find:
$$(n+1) + (N-19) = N+5.$$
This equation is easy to solve and will give you $n=23$, which implies that $N=295$.
You can also derive this easier: increasing the size of the triangle can be achieved by laying down one extra row of balls on one side of the triangle. If you previously had 19 balls to spare and now you are 5 short, that means you were trying to lay down 24 extra balls. Hence, previously your triangle had sides of 23 balls. Then:
$$N=19+\sum_{k=1}^{23}k = 295.$$