Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     char findTheDifference(string &s, string &t) {
  4.         int letterCount[30];
  5.        
  6.         for (int i = 0; i < 30; i++) {
  7.             letterCount[i] = 0;
  8.         }
  9.        
  10.         for (char e : s) {
  11.             letterCount[e - 'a']++;
  12.         }
  13.        
  14.         for (char e : t) {
  15.             letterCount[e - 'a']--;
  16.             if (letterCount[e - 'a'] < 0) {
  17.                 return e;
  18.             }
  19.         }
  20.        
  21.         return '\0';
  22.     }
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement