389 Find the Difference
Last updated
Was this helpful?
Last updated
Was this helpful?
You are given two strings s
and t
.
String t
is generated by random shuffling string s
and then add one more letter at a random position.
Return the letter that was added to t
.
Example 1:
Example 2:
Constraints:
0 <= s.length <= 1000
t.length == s.length + 1
s
and t
consist of lowercase English letters.
还是简单题,因为只有26个字母,就连hashmap都省了,直接上数组。当然return的时候,要cast一下。T:O(N), N是两个string的长度。S:O(1),int[26]。这题一个有趣的地方是,能用那一题的思路来做,用xor。同样的复杂度, T:O(N),S:O(1)