位运算 leecode.389. 找不同

//给定两个字符串 s 和 t,它们只包含小写字母。

  //字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。

  //请找出在 t 中被添加的字母


char
findTheDifference(char* s, char* t) { int len_s = strlen(s); int len_t = strlen(t); if(len_s==0) return *t; char r = t[len_s]; int i =0; for(;i<len_s;i++){ r ^= s[i]^t[i]; } return r; }

猜你喜欢

转载自www.cnblogs.com/czsblog/p/10723341.html