Advertisement
limimage

Find the Difference

Feb 1st, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. class Solution {
  2. public:
  3. char findTheDifference(string s, string t) {
  4. int alp[2][26];
  5. fill(&alp[0][0], &alp[1][26], 0);
  6. for (auto& c: s) {
  7. alp[0][c - 'a']++;
  8. }
  9. for (auto& c: t) {
  10. alp[1][c - 'a']++;
  11. }
  12. for(int i = 0; i < 26; i++) {
  13. if (alp[0][i] != alp[1][i]) {
  14. return static_cast<char>('a' + i);
  15. }
  16. }
  17. return 'a';
  18. }
  19. };
  20.  
  21. //O(|s|) - time and memory complexity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement