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

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

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. python基础-迭代器和生成器

    一.递归和迭代 1.递归:(问路示例) 递归算法是一种直接或者间接地调用自身算法的过程.在计算机编写程序中,递归算法对解决一大类问题是十分有效的,它往往使算法的描述简洁而且易于理解. 2.迭代:简单理 ...

  2. Java中getResourceAsStream的用法

    首先,Java中的getResourceAsStream有以下几种: 1. Class.getResourceAsStream(String path) : path 不以'/'开头时默认是从此类所在 ...

  3. Local gulp not found in.. on windows

    当出现报错时,请按如下方式安装 gulp 以下使用国内的淘宝镜像安装: $ # Step 1 $ cnpm install -g gulp $ # Step 2 $ cnpm install --sa ...

  4. 微信小程序-关于post 过来服务器没有获取到数据问题

    查看一下服务器接收的post 参数是以什么形式接收的 微信给出得demo 请求的方式是Json 参数传递的 所以如果服务器使用的from 表单形式接收数据需要更改微信小程序中的 header 将 he ...

  5. WCF错误:由于目标计算机积极拒绝,无法连接

    今天学习WCF时用C#重写测试例子时,发生错误:由于目标计算机积极拒绝,无法连接.找了N久,网上也没有找到实际的解决方法.查看netstat -an发现当自承载宿主运行时,没有侦听配置的端口.开始总以 ...

  6. VOC2007检测任务的评估标准

    VOC2007数据集使用mAP值作为检测算法检测结果的性能评估得分.mAP意思是mean Average Precision,Precision是指精度,Average Precision是指11个等 ...

  7. Zabbix性能优化

    前言 如果不做表分区和删除历史数据规则设置的话,随着时间的推移zabbix的查询性能会变得很低 查看zabbix的性能 通过zabbix的NVPS(每秒处理数值数)来衡量其性能,在zabbix的das ...

  8. 学习笔记——git

    恩没错,又是个新东西 使用Git提交文件到版本库有两步: 第一步:是使用 git add 把文件添加进去,实际上就是把文件添加到暂存区. 第二步:使用git commit提交更改,实际上就是把暂存区的 ...

  9. Alpha阶段第十次Scrum Meeting

    情况简述 Alpha阶段第十次Scrum Meeting 敏捷开发起始时间 2016/11/3 00:00 敏捷开发终止时间 2016/11/4 00:00 会议基本内容摘要 详细定义了API接口,汇 ...

  10. ionic ios发布图标启动也不能正确加载问题

    前两天发布ios的时候发现ios安装的图标和启动页的时候不能正确显示,重新发布也不能正确显示,修改方法 在ionic build ios --release之前执行ionic resources即可