LeetCode知识点总结 - 389

LeetCode 389. Find the Difference

考点 难度
Hash Table Easy
题目

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.

思路

不需要存储st里面的字母。

答案
public char findTheDifference(String s, String t) {
        int total = 0;
        for(int n:s.toCharArray())
            total+=n;
        for(int n:t.toCharArray())
            total-=n;
        return (char)Math.abs(total);
    }

**解法参考

猜你喜欢

转载自blog.csdn.net/m0_59773145/article/details/120185959