LeetCode_389-Find the Difference
2017-03-04 18:45
435 查看
Solution:
思路:添加不同字符到s再与t比较
char findTheDifference(string s, string t) {
if(s.empty()){
return t[0];
}
string ss;
for(int i = 0; i<26; i++) {
ss = s;
ss.resize(t.size(),(char)('a'+i));
sort(ss.begin(),ss.end());
sort(t.begin(),t.end());
// cout<<ss<<", "<<t<<" "<<(char)('a'+i)<<endl;
if(t==ss) {
// cout<<ss<<", "<<t<<" "<<(char)('a'+i)<<endl;
return (char)('a'+i);
}
}
}
思路:编码解码的思想
char findTheDifference(string s, string t) {
char r=0;
for(char c:s) r ^=c;
for(char c:t) r ^=c;
return r;
}
思路:添加不同字符到s再与t比较
char findTheDifference(string s, string t) {
if(s.empty()){
return t[0];
}
string ss;
for(int i = 0; i<26; i++) {
ss = s;
ss.resize(t.size(),(char)('a'+i));
sort(ss.begin(),ss.end());
sort(t.begin(),t.end());
// cout<<ss<<", "<<t<<" "<<(char)('a'+i)<<endl;
if(t==ss) {
// cout<<ss<<", "<<t<<" "<<(char)('a'+i)<<endl;
return (char)('a'+i);
}
}
}
思路:编码解码的思想
char findTheDifference(string s, string t) {
char r=0;
for(char c:s) r ^=c;
for(char c:t) r ^=c;
return r;
}
相关文章推荐
- LeetCode389. Find the Difference简单
- LeetCode—389. Find the Difference
- [leetcode]389. Find the Difference -- JavaScript 代码
- Leetcode 389 Find the Difference
- LeetCode笔记:389. Find the Difference
- LeetCode(389) Find the Difference
- leetcode 389. Find the Difference 牛人用异或 或者 求和 解决,很简单。
- LeetCode 389:Find the Difference
- Leetcode 389 Find the Difference
- Leetcode 389. Find the Difference
- leetcode:bits:Find the Difference(389)
- [leetcode] 389. Find the Difference 解题报告
- 【leetcode】389. Find the Difference【E】
- leetcode 389. Find the Difference 解题报告
- LeetCode[389]Find the Difference
- Leetcode 389. Find the Difference 找不同 解题报告
- LeetCode : 389. Find the Difference
- leetcode 389 Find the Difference C++
- 【leetcode】389. Find the Difference
- leetcode之389. Find the Difference(C++解法)