Given two strings s and t which consist of only lowercase letters.

String t is generated by random shuffling string s and then add one more letter at a random position.

Find the letter that was added in t.

Example:

Input:
s = "abcd"
t = "abcde" Output:
 class Solution {
public char findTheDifference(String s, String t) {
int res = 0;
for (char c : s.toCharArray()) {
res ^= c - 'a';
}
for (char ch : t.toCharArray()) {
res ^= ch - 'a';
}
return (char)(res + 'a');
}
}
e

Explanation:
'e' is the letter that was added.

[LC] 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. LC 539. Minimum Time Difference

    Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...

  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

    -------------------------------------------------- 先计算每个字母的出现次数然后减去,最后剩下的那一个就是后来添加的了. AC代码: public c ...

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

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

  6. 389. Find the Difference

    一开始没看见shuffle...觉得同时遍历不就完事了.. 和那个所有数字出现2,有一个出现3次还是什么的一样,CHAR可以完美和INT相互切换. public class Solution { pu ...

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

  8. LeetCode 389 Find the Difference 解题报告

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

  9. [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 ...

随机推荐

  1. 加速软件源更新和安装 ubuntu 软件中心

    Linux mint 12 修改加速软件源更新和安装 ubuntu 软件中心 由于 linux mint 12 是基于 ubuntu 的,可以使用 ubuntu 的源(Ubuntu 11.10 代号 ...

  2. vue验证时间范围

    验证时间范围 type="daterange" <DatePicker class="formItem" :size="size" v ...

  3. jquery 第二节 Dom和jQuery的互相转换

    1.Dom转jQuery Dom对象: var v_dom = document.getElementById("name"); 转换: jQuery对象:    var v_jq ...

  4. python 手动安装模块

    python中 openpyxl是解析 excel 文件的模块,一般使用pip install openpyxl 就可以安装. 但是如果处于公司内网时是无法连网安装的,下面就手动安装进行说明: 1.h ...

  5. MySQL--存储引擎的特性

    常用存储引擎的对比 特点 MyISAM InnoDB MEMORY MERGE NDB 存储限制 有 64TB 有 没有 有 事务安全   支持       锁机制 表锁 行锁 表锁 表锁 行锁 B树 ...

  6. 小白学习之pytorch框架(1)-torch.nn.Module+squeeze(unsqueeze)

    我学习pytorch框架不是从框架开始,从代码中看不懂的pytorch代码开始的 可能由于是小白的原因,个人不喜欢一些一下子粘贴老多行代码的博主或者一些弄了一堆概念,导致我更迷惑还增加了畏惧的情绪(个 ...

  7. 复杂json解析方式[GsonFormat]

    针对开发人员来讲,善于用工具,事半功倍. 干货: 1.IntelliJ IDEA 通过GsonFormat插件将JSONObject格式的String 解析成实体 插件地址:https://plugi ...

  8. Apache Commons Lang之日期时间工具类

    码农不识Apache,码尽一生也枉然. FastDateFormat FastDateFormat是一个快速且线程安全的时间操作类,它完全可以替代SimpleDateFromat.因为是线程安全的,所 ...

  9. 常见 Web 安全攻防总结

    Web 安全的对于 Web 从业人员来说是一个非常重要的课题,所以在这里总结一下 Web 相关的安全攻防知识,希望以后不要再踩雷,也希望对看到这篇文章的同学有所帮助.今天这边文章主要的内容就是分析几种 ...

  10. python处理nii格式文件

    网上已经有很多代码了,但是注释的都不全,看起来很费解,我自己加了一些注释,重新发出来,尽可能的通俗易懂 读取前需要先安装库 pip install nibabel pip install matplo ...