Hello.
I’m looking the brute-force solution, and can’t realise why do we need to use outer loop(line 7):
We could use just a variable and one loop, like here:
private static int[] findSum(int[] arr1, int n) {
int i = 0;
for (int j = i + 1; j < arr1.length; j++) {
if (arr1[i] + arr1[j] == n) {
return new int[]{arr1[i], arr1[j]};
}
}
return new int[0];
}
Is it change the time complexity?
Type your question above this line.
Course: https://www.educative.io/collection/5642554087309312/5724822843686912
Lesson: https://www.educative.io/collection/page/5642554087309312/5724822843686912/5747933660053504