--------------------------------------------------

先计算每个字母的出现次数然后减去,最后剩下的那一个就是后来添加的了。

AC代码:

public class Solution {
public char findTheDifference(String s, String t) {
int book[]=new int[26];
for(int i=0;i<s.length();i++) book[s.charAt(i)-'a']++;
for(int i=0;i<t.length();i++) book[t.charAt(i)-'a']--;
for(int i=0;i<book.length;i++) if(book[i]!=0) return (char)(i+'a');
return ' ';
}
}

题目来源: https://leetcode.com/problems/find-the-difference/

LeetCode之389. Find the Difference的更多相关文章

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

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

  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. 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 random s ...

  5. 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 ...

  6. LeetCode 389 Find the Difference 解题报告

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

  7. [LeetCode&Python] Problem 389. Find the Difference

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

  8. 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 ...

  9. LeetCode: 389 Find the Difference(easy)

    题目: Given two strings s and t which consist of only lowercase letters. String t is generated by rand ...

随机推荐

  1. Androidstudio安装AVD出现no system images installed for this target解决方案

    解决方案:

  2. winform采集网站美女图片程序---多线程篇

    设定思路: 采集目标: http://www.8kmm.com,   已知网址列表(List保存),  应用多线程(Thread)读取该列表, 获取url时不能重复(加锁Lock). 允许无序采集! ...

  3. linux下ftp的配置

    最近公司要用到ftp,小菜鸡百度了一下教程,自己也总结一下 现在随便百度都是vsftpd的服务,所以这里我也是用vsftp 1.检测或安装vsftp 首先检查一下你的主机是否含有vsftp服务,关于r ...

  4. ASP.NET MVC 必须设置 ErrorMessageString 或 ErrorMessageResourceName,但不能同时设置二者。

    解决方案: 1.此错误是指你的验证错误信息为空(required="")和required提示信息一致,引发的错误. 简单的来说就是两个验证错误提示消息一样了. 2.修改提示消息解 ...

  5. c# WebClient Get Post 方法

    public string GetData(string url) { string data; using (var client = new WebClient()) { using (var s ...

  6. BZOJ1572 工作安排 USACO2009

    描述 Description     Farmer John 有太多的工作要做啊!!!!!!!!为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间.他的工作日从0时刻开始,有100000 ...

  7. Alpha阶段第六次Scrum Meeting

    情况简述 Alpha阶段第六次Scrum Meeting 敏捷开发起始时间 2016/10/27 00:00 敏捷开发终止时间 2016/10/28 00:00 会议基本内容摘要 提出了目前阶段遇到的 ...

  8. Javascript:一个屌丝的逆袭

    HTML负责结构, CSS负责展示, 而我(加上AJAX, JSON) 负责逻辑.于是前端编程三剑客形成了. http://mp.weixin.qq.com/s?__biz=MzAxOTc0NzExN ...

  9. 在Activity之间传递参数(二)

    传递数据包bundle: 1.MainActivity.class: findViewById(R.id.btnStartAty).setOnClickListener(new View.OnClic ...

  10. 不要在控制台上使用 let/const

    考虑下面的这三句代码和对应的报错信息: 假设写这个代码的人一开始不知道 ES6 里新增的构造函数不能省略 new,于是第一行写错了.然后第二行尝试重新声明一次,结果又报错说重复声明了.那干脆不声明,直 ...