楼主:
yam276 ('_')
2023-09-26 16:12:39※ 引述《Rushia (みけねこ的鼻屎)》之铭言:
: https://leetcode.com/problems/find-the-difference/description
: 389. Find the Difference
: 给你一个字串 s 和 t,t 是 s 字串字符乱序并加上一个字符组成的,返回这个被加上
: 的字符。
思路:
用XOR
因为(a⊕a)⊕(b⊕b)⊕c=0⊕0⊕c=c
impl Solution {
pub fn find_the_difference(s: String, t: String) -> char {
let mut result = 0u8;
for c in s.bytes() {
result ^= c;
}
for c in t.bytes() {
result ^= c;
}
result as char
}
}