Find the Difference - Leetcode 389 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Hashmap Explanation
2:23 - Hashmap Code
3:56 - ASCII Explanation
5:43 - ASCII Code
6:48 - Bit Manipulation Explanation
9:58 - Bit Manipulation Code

leetcode 389

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

Wow, exactly what I needed! Also, for those who don't know, XOR operation is both associative and commutative, therefore, the sequence of characters will not affect the output.

gaychin
Автор

Thank you for the daily problems ! Love the multiple approaches.

MP-nyep
Автор

Bro youre the best, We really appreciate your efforts, Thankyou

michomapeter
Автор

thank you so much for solving the daily challenges !!

ymncore
Автор

The last solution is just mind blowing!

Banaaani
Автор

Thank you for your efforts it's very helpful

houssainebendhieb
Автор

return chr(sum([ord(ch) for ch in t]) - sum([ord(ch) for ch in s])) # one liner

phpostrich
Автор

Did it myself today!!

using the hashing.

char findTheDifference(string s, string t) {

vector<int> mp(27, 0);
char ans = '0';

// we first initialise the vector array with the freq of the characters of string s;
for(auto i=0;i<s.size();i++){
mp[s[i]-'a']++;
}

for(auto i = 0;i<t.size();i++){
mp[t[i]-'a']--;
// if after deleting that character we get a -1 in
//the vector it means that was the unique element.

if(mp[t[i]-'a']==-1){
ans = t[i];
break;
}
}
return ans;
}
S.C. 0(26) ~= O(1). i.e. constant space
T.C. O(N) where N is the size of the string t;

anantom
Автор

my solution:
if s == "":
return t

for i in s:
t = t.replace(i, "", 1)

return t

i think it is easier and more readable 🙃🙃

SASA_maxillo
Автор

I wrote like this

class Solution {
public:
char findTheDifference(string s, string t) {
vector<int>vecS(26, 0);
vector<int>vecT(26, 0);
for(int i=0;i<s.size();i++)
vecS[s[i]-97]++;
for(int i=0;i<t.size();i++)
vecT[t[i]-97]++;
for(int i=0;i<s.size();i++)

return t[i];
return t[t.size()-1];
}
};

rushabhlegion