/*
*
* 给定两个只包含小写字母的字符串 s 和 t 。
*
* 字符串 t 是由随机打乱字符顺序的字符串 s 在随机位置添加一个字符生成。
*
* 找出在 t 中添加的字符。 Input:s = “abcd”,t = “abcde” Output:‘e’ Explanation:‘e’ is the
* letter that was added.
*/
public static char findTheDifference(String s, String t) {
// Write your code here
char res = ' ';
char[] arrs = s.toCharArray();
char[] arrt = t.toCharArray();
Arrays.sort(arrs);
Arrays.sort(arrt);
int index=0;
while(index<arrs.length) {
if (arrs[index] == arrt[index]) {
index++;
}else {
return res = arrt[index];
}
}
return arrt[arrs.length];
}
}