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. Cookie的作用范围、设置、创建、获取的方法

    cookie的作用范围 同一浏览器,同一路径 默认情况下, 上级目录设置的cookie,下级目录可以获取到, 而下级目录设置的cookie,上级目录不能获取. 即:在一个页面设置cookie,那么这个 ...

  2. vue项目开始 首页 part1

    stylus 优点:css之中使用一些变量,方便我们快速编写css 项目中我们使用css开发的辅助工具帮助我们开发网站样式 安装:终端打开我们项目的文件夹 npm install stylus --s ...

  3. mysql 5.6 cmake的安装

    # cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/usr/local/mysql/data \-DSYSCONFDI ...

  4. 用户交互Scanner

    用户交互Scanner java.util.Scanner Scanner类可以获取用户的输入. Java 5 通过Scanner类的next()和nextLine()方法获取输入的字符串 在读取前我 ...

  5. 复杂分布式架构下的计算治理之路:计算中间件 Linkis

    前言 在当前的复杂分布式架构环境下,服务治理已经大行其道.但目光往下一层,从上层 APP.Service,到底层计算引擎这一层面,却还是各个引擎各自为政,Client-Server 模式紧耦合满天飞的 ...

  6. 65)STL中string的知识

    1)代码展示: string是一个类,只不过封装了 char*  而且还封装了  很多的字符串操作函数 2)string类的初始化: string的构造函数 ²  默认构造函数: string();  ...

  7. MVC的异步模式

    [小家Spring]高性能关键技术之---体验Spring MVC的异步模式(Callable.WebAsyncTask.DeferredResult) 基础使用篇 https://blog.csdn ...

  8. 吴裕雄--天生自然 PHP开发学习:多维数组

    <pre> <?php // 二维数组: $cars = array ( array("Volvo",100,96), array("BMW" ...

  9. hasura graphql-engine v1.2.0 beta 版本

    hasura graphql-engine v1.2.0 提供了一个很不错的功能action,这个也是目前其他graphql 没有hasura 强大的 地方,使用action 我们可以更好的扩展has ...

  10. Java之线程通信的应用:经典例题:生产者/消费者问题

    /** * 线程通信的应用:经典例题:生产者/消费者问题 * * 生产者(Productor)将产品交给店员(Clerk),而消费者(Customer)从店员处取走产品, * 店员一次只能持有固定数量 ...