给定两个字符串 s 和 t,它们只包含小写字母。
字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。
请找出在 t 中被添加的字母。
示例:
输入:
s = "abcd"
t = "abcde"
输出:
e
解释:
'e' 是那个被添加的字母。
详见:https://leetcode.com/problems/find-the-difference/description/

C++:

方法一:

class Solution {
public:
char findTheDifference(string s, string t) {
char res=0;
for(char c:s)
{
res^=c;
}
for(char c:t)
{
res^=c;
}
return res;
}
};

方法二:

class Solution {
public:
char findTheDifference(string s, string t) {
unordered_map<char, int> m;
for (char c : s)
{
++m[c];
}
for (char c : t)
{
if (--m[c] < 0)
{
return c;
}
}
return 0;
}
};

389 Find the Difference 找不同的更多相关文章

  1. 389. Find the Difference 找出两个字符串中多余的一个字符

    [抄题]: Given two strings s and t which consist of only lowercase letters. String t is generated by ra ...

  2. 【LeetCode】389 Find the Difference(java)

    原题 Given two strings s and t which consist of only lowercase letters. String t is generated by rando ...

  3. 9. leetcode 389. Find the Difference

    Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...

  4. LeetCode 389 Find the Difference 解题报告

    题目要求 Given two strings s and t which consist of only lowercase letters. String t is generated by ran ...

  5. LeetCode - 389. Find the Difference - 三种不同解法 - ( C++ ) - 解题报告

    1.题目大意 Given two strings s and t which consist of only lowercase letters. String t is generated by r ...

  6. 【leetcode389】389. Find the Difference

    异或 找不同 —.— public class Solution { public char findTheDifference(String s, String t) { char temp = 0 ...

  7. LeetCode389Find the Difference找不同

    给定两个字符串 s 和 t,它们只包含小写字母. 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母. 请找出在 t 中被添加的字母. 示例: 输入: s = "abcd&quo ...

  8. 【LeetCode】389. Find the Difference 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:字典统计次数 方法二:异或 方法三:排序 日 ...

  9. LeetCode 389. Find the Difference

    Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...

随机推荐

  1. SPOJ SUMPRO(数学)

    题意: 给出一个数N,问所有满足n/x=y(此处为整除)的所有x*y的总和是多少.对答案mod(1e9+7). 1 <= T <= 500. 1 <= N <= 1e9. 分析 ...

  2. java MAT 分析

    java MAT 分析 http://blog.csdn.net/qeqeqe236/article/details/43577857 https://www.cnblogs.com/AloneSwo ...

  3. Android之——多线程下载演示样例

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46883927 一.概述 说到Android中的文件下载.Android API中明 ...

  4. 智能社区--HI3516C可视门禁研发出来咯

    铝壳.非常大气的外壳. 200W像素,HI3516C,携带server.创新的产品.欢迎交流:QQ237753582 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5u ...

  5. firewalld filter

    实现 firewalld  的filter 功能 1. 关闭 INPUT ,关闭OUTPUT  (设置黑名单) 任何主机 都 ping 不通 本主机 1>命令 : iptables -P INP ...

  6. 网卡bood

    一.网卡bood (1)网卡bond(绑定),也称作网卡捆绑.就是将两个或者更多的物理网卡绑定成一个虚拟网卡.网卡是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在应用部署 ...

  7. Vijos P1023Victoria的舞会3【贪心+DFS求强联通分量】

    链接:Click Me! P1023Victoria的舞会3 Accepted 标签:Victoria的舞会[显示标签] 描写叙述 Victoria是一位颇有成就的艺术家,他因油画作品<我爱北京 ...

  8. ServiceStack学习之一准备工作

    GitHub:https://github.com/ServiceStack/ServiceStack/wiki 官网介绍的前期准备知识: Wikipedia article about HTTP a ...

  9. iOS MMDrawerController源码解读(一)

      提前说好,本文绝对不是教你如何使用MMDrawerController这个第三方库,因为那太多人写了 ,也太简单了.这篇文章主要带你分析MMDrawerController是怎么实现抽屉效果,明白 ...

  10. Android在onCreate()方法中动态获取TextView控件的高度

    正好朋友项目里遇到了给写了个小Demo: 这个监听器看名字也知道了.就是在绘画完毕之前调用的,在这里面能够获取到行数.当然也能够获取到宽高等信息 package com.example.textvie ...