-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1540.cpp
More file actions
39 lines (38 loc) · 957 Bytes
/
Copy path1540.cpp
File metadata and controls
39 lines (38 loc) · 957 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
class Solution {
public:
void debug(vector<int>& arr){
for(auto& x:arr)
cout<< x << " ";
cout<<"\n";
}
bool canConvertString(string s, string t, int k) {
if(s.size()!=t.size())
return false;
int n = s.size();
int times = k/26;
int rem = k%26;
vector<int> count(26,times);
for(int i=0; i<rem; i++)
count[i]++;
// debug(count);
for(int i=0; i<n; i++){
int x = s[i]-'a';
int y = t[i]-'a';
int curr = y-x;
if(curr==0)
continue;
if(curr<0)
curr += 26;
curr %= 26;
if(curr==0)
curr = 25;
else
curr -= 1;
count[curr]--;
// cout<<curr<<" ";
if(count[curr]<0)
return false;
}
return true;
}
};