The question is – how many three numbers exits (of the provided) that sum to zero?
I’m wondering, how to implement this brute force method (below) in ruby? The main aspect of this is : what is better to use in a place of for loop? times?
a – is array of integers, the data that’s provided
int N = a.length;
int count = 0;
for(int i = 0; i<N; i++)
for(int j = i+1; j<N; j++)
for(int k = j+ 1; k<N; k++)
if (a[i] + a[j] + a[k] == 0 )
count++;
return count;
How about:
But I don’t get the connection with Rails here 😉