美文网首页LeetCode蹂躏集
LeetCode 389. Find the Differenc

LeetCode 389. Find the Differenc

作者: alexsssu | 来源:发表于2018-01-25 12:44 被阅读0次

找出两个string中的单一值,使用异或操作,两个相同的值异或等于零,把两个string中的所有值都做异或操作,最后结果就是单一值。

class Solution {
public:
    char findTheDifference(string s, string t) {
        char c = t.back();
        for (int i = 0; i < s.size(); ++i) {
            c ^= s[i];
            c ^= t[i];
        }
     return c;
    }
};

相关文章

网友评论

    本文标题:LeetCode 389. Find the Differenc

    本文链接:https://www.haomeiwen.com/subject/lthvaxtx.html