-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcodeHelper.h
More file actions
44 lines (37 loc) · 824 Bytes
/
leetcodeHelper.h
File metadata and controls
44 lines (37 loc) · 824 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
33
34
35
36
37
38
39
40
41
42
43
44
#include <string>
#include <vector>
using namespace std;
vector<string> split(string s, char del){
int n = s.size();
s = s.substr(1, n-2);
string temp = "";
vector<string> ans;
for(int i=0; i<s.size(); i++){
if(s[i] == '"') continue;
if(s[i] == del) {
ans.push_back(temp);
temp ="";
}
else temp.push_back(s[i]);
}
ans.push_back(temp);
return ans;
}
int to_int(string s){
bool neg = false;
int i = 0;
if(s[0] == '-') {
i++;
neg = true;
}
int ans = 0;
for(; i<s.size(); i++){
ans = ans*10+(s[i] - '0');
}
return neg ? -ans : ans;
}
vector<int> stringArr_toIntArr(vector<string> arr){
vector<int> ans;
for(auto st: arr) ans.push_back(to_int(st));
return ans;
}