tygarian

find the difference leetcode

Feb 7th, 2022
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. class Solution {
  2. public:
  3. // Time Complexity:- O(max(N,M))
  4. // Space Complexity:- O(26)
  5. char findTheDifference(string s, string t) {
  6. vector<int> dp(26);
  7. for(auto& c:s){
  8. dp[c-'a']++;
  9. }
  10. for(auto& c:t){
  11. if(!dp[c-'a']){
  12. return c;
  13. }
  14. dp[c-'a']--;
  15. }
  16. return 'a';
  17. }
  18. };
Add Comment
Please, Sign In to add comment