389. 找不同
- 题号:389
- 来源:LeetCode
- 难度:简单
- 标签:
位运算字符串 - 语言:TypeScript
- 解法:1 个
- 作者:lmliheng
- 最近更新:2026-09-27
TypeScript · O(n) 时间 · O(1) 空间 · 更新于 2026-09-27
两串字符编码全部异或,剩下就是多的字符
typescript
/**
* @difficulty easy
* @tags 位运算,字符串
* @time O(n)
* @space O(1)
* @note 两串字符编码全部异或,剩下就是多的字符
* @389. 找不同
*/
let s = "abcd"
let t = "abcde"
let res = 0
for (let ch of s) {
res ^= ch.charCodeAt(0)
}
for (let ch of t) {
res ^= ch.charCodeAt(0)
}
console.log(String.fromCharCode(res))在 GitHub 上查看题目所在目录:lmliheng/algorithm