?LeetCode刷題實(shí)戰(zhàn)389:找不同
You are given two strings s and t.
String t is generated by random shuffling string s and then add one more letter at a random position.
Return the letter that was added to t.
示例
示例 1:
輸入:s = "abcd", t = "abcde"
輸出:"e"
解釋:'e' 是那個(gè)被添加的字母。
示例 2:
輸入:s = "", t = "y"
輸出:"y"
示例 3:
輸入:s = "a", t = "aa"
輸出:"a"
示例 4:
輸入:s = "ae", t = "aea"
輸出:"a"
解題
class Solution {
public:
char findTheDifference(string s, string t) {
sort(s.begin(),s.end());
sort(t.begin(),t.end());
int i=0;
while(s[i]==t[i]){
i++;
}
return t[i];
}
};
LeetCode1-380題匯總,希望對(duì)你有點(diǎn)幫助!
LeetCode刷題實(shí)戰(zhàn)381:O(1) 時(shí)間插入、刪除和獲取隨機(jī)元素
LeetCode刷題實(shí)戰(zhàn)382:鏈表隨機(jī)節(jié)點(diǎn)
LeetCode刷題實(shí)戰(zhàn)383:贖金信
LeetCode刷題實(shí)戰(zhàn)384:打亂數(shù)組
LeetCode刷題實(shí)戰(zhàn)385:迷你語法分析器
