-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsumNP.cpp
More file actions
32 lines (27 loc) · 722 Bytes
/
Copy pathsumNP.cpp
File metadata and controls
32 lines (27 loc) · 722 Bytes
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
31
32
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
pair<int, int> sumPositiveNegative(const vector<int>& arr) {
int n = arr.size();
int sum = 0;
int sum1 = 0;
for(int i = 0; i < n; i++) {
if(arr[i] > 0) {
sum += arr[i];
} else {
sum1 += arr[i];
}
}
return {sum, sum1};
}
};
int main() {
vector<int> nums = {6, -9, 3, 5, -8, -2};
Solution sol;
pair<int, int> result = sol.sumPositiveNegative(nums);
cout << "Sum of positive numbers: " << result.first << endl;
cout << "Sum of negative numbers: " << result.second << endl;
return 0;
}