LeetCode
来源:互联网 发布:网络惊魂下载 编辑:程序博客网 时间:2024/06/05 06:32
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:eExplanation:'e' is the letter that was added.
一开始没看懂题,一脸懵逼地以为t是s的子串,然后在那里使劲yy,yy不出来orzzzzzzzzz
最后怀疑人生,这真的是easy么QAQ。。。后来看了评论区。。才懂了题意。。心情好复杂。。。不就是,,,数组中只出现一次的数的改版。。。。
题意:t为s的乱序,然后新添加了一个字母,求这个字母
时间复杂度O(n),空间复杂度O(1)
class Solution {public: char findTheDifference(string s, string t) { char ans = 0; for (int i = 0; i < s.length(); ++i) ans ^= s[i]; for (int i = 0; i < t.length(); ++i) ans ^= t[i]; return ans; }};
阅读全文
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- Intent的简介以及属性的详解
- USB的四种传输类型与端点
- Eclipse历代版本
- hololens开发笔记-DEP6957未能使用“通用身份验证”连接到设备
- C++中的STL中map用法详解
- LeetCode
- Spring中@Controller和@RestController之间的区别
- shell脚本中文注释乱码问题(解决)
- 算法运行时间分析
- 快使用阿里云的maven仓库
- instancesRespondToSelector与respondsToSelector的区别
- ipmi+BMC详解
- SVN导出的项目修改后没有*号
- 指针数组与数组指针