We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
题目描述:
给定两个字符串 s 和 t,它们只包含小写字母。
字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。
请找出在 t 中被添加的字母。
示例:
输入: s = "abcd" t = "abcde" 输出: e 解释: 'e' 是那个被添加的字母。
解题思路:使用哈希表,遍历一遍存数。使用自加来记录出现次数,当为0时,说明没有记录过或者已经超过其重复次数了。test case: s:a. t:aa
C++解题:
class Solution { public: char findTheDifference(string s, string t) { unordered_map<char,int> map; for(char cc : s) map[cc]++; for(char cc:t){ if(map[cc] == 0) return cc; else map[cc]--; } return ' '; } };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目描述:
给定两个字符串 s 和 t,它们只包含小写字母。
字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。
请找出在 t 中被添加的字母。
示例:
解题思路:使用哈希表,遍历一遍存数。使用自加来记录出现次数,当为0时,说明没有记录过或者已经超过其重复次数了。test case: s:a. t:aa
C++解题:
The text was updated successfully, but these errors were encountered: