Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool decode (string s, string t, int &u)
- {
- unordered_map <char, char> used_s;
- unordered_map <char , bool> used_t;
- for (int i = 0 ; i < s.size(); i++)
- {
- char c_s = s[i];
- char c_t = t[i];
- if (used_s.count(c_s) > 0 && used_s[c_s] != c_t)
- {
- cout <<i<<endl;
- return false;
- }
- if (used_t.count(c_t) == 0)
- u++;
- used_t[c_t] = true;
- used_s[c_s] = c_t;
- }
- return true;
- }
- bool canConvert(string str1, string str2) {
- int used_l = 0;
- return str1 == str2 || (decode(str1,str2, used_l) && used_l < 26);
- }
- };
- /*
- constrains
- lowercase
- same size
- s = aabbc => 11223
- t = ccdde => 11223
- s => ab => 12
- t => ba => 12 return true;
- s=> ab => bb => aa return false;
- 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
- "a b c d e f g h i j k l m n o p q r s t u v w x y z"
- "b c d e f g h i j k l m n o p q r s t u v w x y z a"
- 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
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement