-
Notifications
You must be signed in to change notification settings - Fork 10
/
Day-260.cpp
33 lines (33 loc) · 915 Bytes
/
Day-260.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
31
32
33
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
vector<int> getArray(vector<char>&v) {
int negCounter = count_if(v.begin(), v.end(), [](char ch) { return ch=='-';});
int start = negCounter;
vector<int> ans(v.size(), -1);
ans[0] = start++;
--negCounter;
for (int i=1; i<(int)v.size(); ++i) {
if (v.at(i) == '+') {
ans.at(i) = start++;
} else {
ans.at(i) = negCounter--;
}
}
return ans;
}
};
int main(void){
// vector<char> v{'*', '+' , '+' , '-', '+'};
vector<char> v{'*', '-', '-', '-', '+', '+'};
Solution s;
vector<int> sol = s.getArray(v);
for (auto&itr:sol) {
cout << itr <<' ';
}
cout << '\n';
return 0;
}