[LeetCode] 389 Find the Difference 解题思路 字符查找
来源:互联网 发布:plc编程软件下载 编辑:程序博客网 时间:2024/06/07 14:43
思路1:
遍历t中的每个char,若char在s中出现,则将s中相同的char删除,最后t中新插入的char一定不存在s中,代码如下:
s.find(a)函数是string的查找函数,若s中存在a,则返回a在s中的位置,若s中不存在a,返回npos,表示不存在的位置
s.erase(pos,len) 删除从位置pos开始的len字符
该方法运行时间为9ms,时间成本相对较高,
思路2:
看到LeetCode上的Discuss有人用异或Xor,具体代码如下:
该方法其实是将s和t加起来,所有char进行Xor,同时Xor满足交换律:
阅读全文
0 0
- [LeetCode] 389 Find the Difference 解题思路 字符查找
- [leetcode] 389. Find the Difference 解题报告
- leetcode 389. Find the Difference 解题报告
- 【LeetCode】Find the Difference 解题报告
- [Leetcode] 389. Find the Difference 解题报告
- LeetCode 389 Find the Difference
- Leetcode 389 Find the Difference
- Leetcode 389 Find the Difference
- LeetCode[389]Find the Difference
- LeetCode 389:Find the Difference
- Leetcode 389 Find the Difference
- [LeetCode-389]Find the Difference
- Leetcode 389 Find the Difference
- leetcode-389-find the difference
- leetcode 389 Find the Difference
- Leetcode #389 Find the Difference
- Leetcode 389 Find the Difference
- LeetCode.389 Find the Difference
- 练习题2(17.09.06)
- 如何制作Excel表头
- POJ2559.md
- struts2-->validate 和 interceptor
- python
- [LeetCode] 389 Find the Difference 解题思路 字符查找
- VMware虚拟机下安装CentOS7.0图文教程
- hdu5073 数学化简
- RMQ Problem.md
- 如何在移动开发者的寒冬中破冰而出?
- PhotoView图片查看器
- Android -开启GPS权限
- STM32 FSMC LCD 液晶的驱动—ILI9320
- 堆的使用