-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathSave net
65 lines (33 loc) · 890 Bytes
/
Save net
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Solution{
public:
string maxSum(string w,char x[], int b[],int n){
int ans = INT_MIN, curr=0;
string res = "", s="";
unordered_map<char,int> m;
for(int i=0;i<n;i++){
m[x[i]] = b[i];
}
for(int i=0;i<w.size();i++){
if(m.find(w[i]) != m.end()){
curr += m[w[i]];
}
else{
if(w[i]>='a' && w[i]<='z')
curr += w[i];
else{
curr += w[i];
}
}
s += w[i];
if(ans<curr){
ans = curr;
res = s;
}
if(curr<0){
curr=0;
s="";
}
}
return res;
}
};