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

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

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. 动画的使用—View Animation

    View Animation定义了下面的四种动画效果: 缩放(scale).位移(translation).旋转(rotation).透明(alpha)   缩放动画: ScaleAnimation( ...

  2. 图解Javascript原型链

    本文尝试阐述Js中原型(prototype).原型链(prototype chain)等概念及其作用机制.上一篇文章(图解Javascript上下文与作用域)介绍了Js中变量作用域的相关概念,实际上关 ...

  3. layer弹窗监控键盘事件

    在开发中我们常常遇到客服各种其他问题,现在客服需要键盘按下关闭当前窗口事件和鼠标点击确定按钮事件一样. 我们需要在layer中编写一个监控事件.具体代码如下 layer.confirm('is not ...

  4. Maven代理教程

    明确代理服务器地址及端口,比如proxy.supremehover.com:8080 找到maven目录下的conf\settings.xml并打开,在proxies节点下添加proxy <pr ...

  5. [C#] 将 List 转 DataTable

    /// <summary> /// Convert a List{T} to a DataTable. /// </summary> private DataTable ToD ...

  6. 微信学习总结 09 解析接口中的消息创建时间CreateTime

    1 消息的创建时间 网页超链接的作用以及如何在文本消息中使用网页超链接 2. 具体实现 刘峰博主的博文已经分析的很清楚了,直接去看就行了 .http://blog.csdn.net/lyq8479/a ...

  7. WEKA使用

    参考 http://bbs.middleware123.com/thread-24052-1-1.html  使用Weka进行数据挖掘 http://quweiprotoss.blog.163.com ...

  8. 优化Table View

    优化Table View Table view需要有很好的滚动性能,不然用户会在滚动过程中发现动画的瑕疵. 为了保证table view平滑滚动,确保你采取了以下的措施: 正确使用`reuseIden ...

  9. json 对象 字符串 转换

    json字符串转json对象:jQuery.parseJSON(jsonStr); json对象转json字符串:JSON.stringify(jsonObj);

  10. 最简单的STM32入门教程----闪烁LED

    本文讲述的是如何从零开始,使用keil建立一个简单的STM32的工程,并闪烁LED灯,给小白看. 第零步,当然首先你得有一个STM32的板子,其IO口上接了一个LED... 第一步,建立一个文件夹0. ...