Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- // Time Complexity:- O(max(N,M))
- // Space Complexity:- O(26)
- char findTheDifference(string s, string t) {
- vector<int> dp(26);
- for(auto& c:s){
- dp[c-'a']++;
- }
- for(auto& c:t){
- if(!dp[c-'a']){
- return c;
- }
- dp[c-'a']--;
- }
- return 'a';
- }
- };
Add Comment
Please, Sign In to add comment