精華區beta Marginalman 關於我們 聯絡資訊
※ 引述《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 } } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.251.123.162 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1695715961.A.8ED.html
Rushia: 大師 09/26 16:18
NTHUlagka: 大師 09/26 16:38