problem
給定兩字串,字串t比字串s多出一個字元,將他找出來
solution
- 逐一字串 t 拜訪,拜訪到的字元將轉其對應ASCII 取值,並累加
- 逐一字串 s 拜訪,拜訪到的字元將轉其對應ASCII 取值,並相減
1 | class Solution { |
- 遍歷字串s,t,對所有字元做xor
1 | class Solution { |
analysis
- time complexity
O(n)
- space complexity
O(1)
給定兩字串,字串t比字串s多出一個字元,將他找出來
1 | class Solution { |
1 | class Solution { |
O(n)
O(1)