LeetCode 389. 找不同
题目描述
✅ 389. 找不同
思路分析
异或运算
参考代码
1
2
3
4
5
6
7
8
9
10
func findTheDifference(s string, t string) byte {
var res byte = 0
for i := 0; i < len(s); i++ {
res ^= s[i]
}
for i := 0; i < len(t); i++ {
res ^= t[i]
}
return res
}
- 时间复杂度:O(n),其中 n 是字符串 s 的长度。
- 空间复杂度:O(1),只使用了常数级别的额外变量。
1
write your code here
1
write your code here
CC BY-NC-SA 4.0
许可协议,转载请注明出处!
本博客所有文章除特别声明外,均采用