Files
2020-08-09 00:39:24 +08:00

31 lines
897 B
Markdown
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# [389. Find the Difference](https://leetcode.com/problems/find-the-difference/)
## 题目
Given two strings **s** and **t** which consist of only lowercase letters.
String **t** is generated by random shuffling string **s** and then add one more letter at a random position.
Find the letter that was added in **t**.
**Example:**
Input:
s = "abcd"
t = "abcde"
Output:
e
Explanation:
'e' is the letter that was added.
## 题目大意
给定两个字符串 s 和 t它们只包含小写字母。字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。请找出在 t 中被添加的字母。
## 解题思路
- 题目要求找出 t 字符串中比 s 字符串多出的一个字符。思路还是利用异或的性质,`X^X = 0`,将 s 和 t 依次异或,最终多出来的字符就是最后异或的结果。