-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path138.cpp
30 lines (30 loc) · 848 Bytes
/
138.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
public:
/**
* @param nums: A list of integers
* @return: A list of integers includes the index of the first number and the index of the last number
*/
vector<int> subarraySum(vector<int> &nums) {
// write your code here
int len = nums.size();
vector<int> res;
if(len == 0) return res;
for(int i = 0; i < len; i++) {
sum = nums[i];
if(sum == 0) {
res.push_back(i);
res.push_back(i);
return res;
}
for(int j = i + 1; j < len; j++) {
sum += nums[j];
if(sum == 0) {
res.push_back(i);
res.push_back(j);
return res;
}
}
}
return res;
}
};