[LC] 389. Find the Difference
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的更多相关文章
- 389. Find the Difference 找出两个字符串中多余的一个字符
[抄题]: Given two strings s and t which consist of only lowercase letters. String t is generated by ra ...
- LC 539. Minimum Time Difference
Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...
- 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
-------------------------------------------------- 先计算每个字母的出现次数然后减去,最后剩下的那一个就是后来添加的了. AC代码: public c ...
- 【LeetCode】389 Find the Difference(java)
原题 Given two strings s and t which consist of only lowercase letters. String t is generated by rando ...
- 389. Find the Difference
一开始没看见shuffle...觉得同时遍历不就完事了.. 和那个所有数字出现2,有一个出现3次还是什么的一样,CHAR可以完美和INT相互切换. public class Solution { pu ...
- 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 ...
随机推荐
- Spring源码解读:核心类DefaultListableBeanFactory的继承体系
1 简介 我们常用的ClassPathXmlApplicationContext是AbstractRefreshableApplicationContext的子类,而DefaultListableBe ...
- Linux--Centos7开机启动 mysql5.7.19
参考:http://www.cnblogs.com/Anker/p/3551508.html
- YouTube推出慈善组合工具,能引国内视频网站跟风吗?
互联网的出现不仅仅让大众的工作和生活更便利,更深度改变着传统事物的形态,让其被更多人广泛地认知并接触到.如,原本在线下通过彩页.手册.横幅等进行宣传.募捐的慈善,就通过互联网展现出更为强大的影响力.而 ...
- 修复grub
进入命令行模式,#chroot /mnt/sysimage :切换根目录#grub2-install /dev/sda :安装grub2到第一硬盘#grub2-mkconfig -o /boot/gr ...
- 4. react 基础 - 编写 todoList 功能
编写 TodoList 功能 react 入口 js #src/index.js import React from 'react'; import ReactDOM from 'react-dom' ...
- 用IMX6开发板创建Android模拟器
基于迅为IMX6开发板 在 AndroidStudio 中,单击“Tools”->“Android”->“AVD Manager”选项.弹出 如下对话框,点击红色方框中的按钮. 弹出如下所 ...
- SpringSecurity过滤器顺序
https://blog.csdn.net/qq_35720307/article/details/97656608 org.springframework.security.config.annot ...
- C/C++ 取整函数ceil(),floor()
使用floor函数.floor(x)返回的是小于或等于x的最大整数.如: floor(10.5) == 10 floor(-10.5) == -11 使用ceil函数.ceil(x)返回 ...
- CSP模拟赛3游记
老师说这次题比较难,深表同意,还是只有90min. T1有还几个坑点,呜呜呜,感觉有点像斗地主的超级简化版. T2:不难但是特别复杂需要70+行代码,比龙虎斗好想但比较难写,但还是成功打挂. T3:根 ...
- 小白学习之pytorch框架(6)-模型选择(K折交叉验证)、欠拟合、过拟合(权重衰减法(=L2范数正则化)、丢弃法)、正向传播、反向传播
下面要说的基本都是<动手学深度学习>这本花书上的内容,图也采用的书上的 首先说的是训练误差(模型在训练数据集上表现出的误差)和泛化误差(模型在任意一个测试数据集样本上表现出的误差的期望) ...