Advertisement
SalmaYasser

Untitled

Jan 7th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. class Solution {
  2. public:
  3.  
  4. bool decode (string s, string t, int &u)
  5. {
  6. unordered_map <char, char> used_s;
  7. unordered_map <char , bool> used_t;
  8.  
  9. for (int i = 0 ; i < s.size(); i++)
  10. {
  11.  
  12. char c_s = s[i];
  13. char c_t = t[i];
  14.  
  15. if (used_s.count(c_s) > 0 && used_s[c_s] != c_t)
  16. {
  17. cout <<i<<endl;
  18. return false;
  19. }
  20. if (used_t.count(c_t) == 0)
  21. u++;
  22. used_t[c_t] = true;
  23. used_s[c_s] = c_t;
  24. }
  25.  
  26. return true;
  27. }
  28. bool canConvert(string str1, string str2) {
  29.  
  30. int used_l = 0;
  31. return str1 == str2 || (decode(str1,str2, used_l) && used_l < 26);
  32.  
  33. }
  34. };
  35.  
  36. /*
  37.  
  38. constrains
  39. lowercase
  40. same size
  41.  
  42. s = aabbc => 11223
  43. t = ccdde => 11223
  44.  
  45. s => ab => 12
  46. t => ba => 12 return true;
  47.  
  48. s=> ab => bb => aa return false;
  49.  
  50.  
  51. 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
  52. "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"
  53.  
  54. "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"
  55. 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
  56.  
  57.  
  58.  
  59. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement