package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev
# README
389. Find the Difference
Solution idea
HashMap / Array of length 26
- 用 HashMap/Array of Length 26 记录
s
中出现的字母,查询t
中哪个字母没出现
Time complexity = $O(n)$
XOR - 同性相消
利用异或的性质,X^X = 0
,将 s 和 t 依次异或,最终多出来的字符就是最后异或的结果。
Resource
-
array of length 26: 贾考博 LeetCode 389. Find the Difference - 工作随便找系列2
-
XOR: halfrost/LeetCode-Go