Right sorry about that. I meant O(n^2) thanks for the correction!
J
jj17
@jj17
0
Reputation
2
Posts
60
Profile views
0
Followers
0
Following
Posts made by jj17

RE: Continous Subarray Sum

RE: Continous Subarray Sum
I must be missing something. In the first brute force approach, what purpose does having three loops serve?
isn't it sufficient to use two loops?
for (int i = 0; i < nums.length; i++) {
int sum = 0;
for (int j = i; j < nums.length; j++) {
sum += nums[j];
// Check condition
}
}
This would cover all possible contiguous subarray sums in my mind and offers a O(n) time O(1) space bruteforce solution. I must be missing something.