分类网站 php,网站建设优化服务咨询,西安网站推广招聘网,全国中高风险地区最新名单给定两个字符串 s 和 t#xff0c;它们只包含小写字母。
字符串 t 由字符串 s 随机重排#xff0c;然后在随机位置添加一个字母。
请找出在 t 中被添加的字母。 示例:
输入#xff1a; s abcd t abcde
输出#xff1a; e
解释#xff1a; …给定两个字符串 s 和 t它们只包含小写字母。
字符串 t 由字符串 s 随机重排然后在随机位置添加一个字母。
请找出在 t 中被添加的字母。 示例:
输入 s abcd t abcde
输出 e
解释 e 是那个被添加的字母。
全部异或一遍因为自己和自己异或为0异或满足交换律所以这样做的结果就是答案。
class Solution {public char findTheDifference(String s, String t) {char result 0;for (char i:s.toCharArray())result ^ i;for (char i:t.toCharArray())result ^ i;return result;}
}