389. Find the Difference 难度:easy
来源:互联网 发布:中国阶级 知乎 编辑:程序博客网 时间:2024/05/18 01:35
题目:
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的基础上多加了一个字符,要求我们找出那个字符。将s和t当作一个整体,除了一个字符其余字符都出现了两次,即可对s和t的每个字符进行异或操作,最后的结果就是单独的那个字符。
程序:
class Solution {public: char findTheDifference(string s, string t) { char res = 0x00; for(int i = 0;i < s.size();i++) res ^= s[i]; for(int i = 0;i < t.size();i++) res ^= t[i]; return res; }};
0 0
- 389. Find the Difference 难度:easy
- Leetcode 389. Find the Difference (Easy) (cpp)
- 389. Find the Difference [easy] (Python)
- leetcode389[easy]---Find the Difference
- 389.leetcode Find the Difference(easy)[字符串处理]
- 【leetcode】【Easy】【389. Find the Difference】【string】【bit manipulation】
- Find the difference——Difficulty:Easy
- Easy 389题 Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference*
- 有时间细读这些书
- Looper详解--Android消息机制之4
- 不得不提的volatile及指令重排序(happen-before)
- 第七周能否构成三角形
- hrbust 1758 Minimum Window Substring【尺取法】好题
- 389. Find the Difference 难度:easy
- Local Feature Detection and Extraction
- C++ Primer 5th 课后习题8.10、8.11、8.13
- 数组
- C#32课的主要内容
- UVA10763--ForeignExchange
- 无头单链表的所有操作(包含面试题)
- 迭代, 瀑布, 到底差別在那?
- 【罗兰のJava学习笔记】第六天,初识面向对象