Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Time Complexity: O(n) where n is t.size() + s.size()
- // Memory Complexity: O(1)
- class Solution {
- public:
- char findTheDifference(string s, string t) {
- vector<int> counters(256, 0);
- assert(t.size() - s.size() == 1);
- for (auto c : t) {
- counters[c - 'a']++;
- }
- for (auto c : s) {
- counters[c - 'a']--;
- }
- for (int i = 0; i < 256; i++) {
- if (counters[i] > 0) {
- return 'a' + i;
- }
- }
- assert(false);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement