LeetCode之389. Find the Difference

--------------------------------------------------
先计算每个字母的出现次数然后减去,最后剩下的那一个就是后来添加的了。
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的更多相关文章
- 【LeetCode】389. Find the Difference 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:字典统计次数 方法二:异或 方法三:排序 日 ...
- 【LeetCode】389 Find the Difference(java)
原题 Given two strings s and t which consist of only lowercase letters. String t is generated by rando ...
- LeetCode 389. Find the Difference (找到不同)
Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...
- LeetCode 389. Find the Difference
Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...
- 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 ...
- LeetCode 389 Find the Difference 解题报告
题目要求 Given two strings s and t which consist of only lowercase letters. String t is generated by ran ...
- [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 ...
- 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 ...
- LeetCode: 389 Find the Difference(easy)
题目: Given two strings s and t which consist of only lowercase letters. String t is generated by rand ...
随机推荐
- Mysql 索引实现原理. 聚集索引, 非聚集索引
Mysql索引实现: B-tree,B是balance,一般用于数据库的索引.使用B-tree结构可以显著减少定位记录时所经历的中间过程,从而加快存取速度.而B+tree是B-tree的一个变种,My ...
- Git和Github简单教程
原文链接:Git和Github简单教程 网络上关于Git和GitHub的教程不少,但是这些教程有的命令太少不够用,有的命令太多,使得初期学习的时候需要额外花不少时间在一些当前用不到的命令上. 这篇文章 ...
- Git 本地项目上传至托管平台(OsChina/GitHub)
为了方便自己的代码管理,通常是把自己的写的一些小项目分享到GitHub 或者git.oschina上面! 区别: GitHub 只能创建公开的项目,国外的,速度慢! git.oschina 开源中国的 ...
- Vue之计算属性
上一篇里演示了计算属性的优点,但是,computed和data里的属性还是有区别的,computed的一个弱点就在于依赖于data属性的更新,才能触发视图更新. 举个例子: 上个例子中谈到用v-for ...
- 使用css3 实现太阳升起落下效果
<!DOCTYPE html><html style="overflow: hidden"><head> <meta http-equiv ...
- 清除文件夹下的SVN信息
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE/SOFTWARE/Classes/Folder/shell/清除SVN信息] @=&q ...
- Ubuntu 14.04 LTS 安装 spark 1.6.0 (伪分布式)-26号开始
需要下载的软件: 1.hadoop-2.6.4.tar.gz 下载网址:http://hadoop.apache.org/releases.html 2.scala-2.11.7.tgz 下载网址:h ...
- 调试使用windows堆程序遇到的问题
今天测试我的api hook demo,中间有个单向链表,我对他进行遍历的时候,通过判断链表当前元素是否为NULL(即0)来进行循环控制,在cmd下正常运行,输出的是:,struct addr is ...
- pycloudtag 标签云
原创,转载请标明 QQ:231469242 # -*- coding: utf-8 -*- """Python3.0 Created on Sat Nov 26 08:5 ...
- sicp-py
第一章 在第一章中,我们专注于计算过程,以及程序设计中函数的作用.我们看到了如何使用原始数据(数值)和原始操作(算术运算),如何通过组合和控制来形成复合函数,以及如何通过给予过程名称来创建函数抽象.我 ...