Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- char findTheDifference(string s, string t) {
- int alp[2][26];
- fill(&alp[0][0], &alp[1][26], 0);
- for (auto& c: s) {
- alp[0][c - 'a']++;
- }
- for (auto& c: t) {
- alp[1][c - 'a']++;
- }
- for(int i = 0; i < 26; i++) {
- if (alp[0][i] != alp[1][i]) {
- return static_cast<char>('a' + i);
- }
- }
- return 'a';
- }
- };
- //O(|s|) - time and memory complexity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement