[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 ...
随机推荐
- TextView和Button的学习
常用属性,界面跳转,按钮学习,按压颜色的变换,图片的插入学习等 工程目录: MainActivity.java: package com.example.revrse; import androidx ...
- Pyspider的简单介绍和初使用
Pyspider Pyspider是由国人(binux)编写的强大的网络爬虫系统 Ptspider带有强大的WebUi / 脚本编辑器 / 任务监控器 / 项目管理器以及结果处理器.他支持多种数据 ...
- 小程序Java多次请求Session不变
微信小程序每次请求的sessionid是变化的,导致对应后台的session不一致,无法获取之前保存在session中的openid和sessionKey. 为了解决这个问题,需要强制同意每次小程序前 ...
- UML-交互图包含哪些图?
猫比狗精明,但你无法让8只猫在雪地里拉雪橇---杰夫.瓦尔德斯 本章是重点. 1.总览 2.顺序图 1).类A具有doOne方法和类B的属性 2).doOne方法中调用类B的doTwo()和doThr ...
- Python—选择排序算法
# 选择排序,时间复杂度O(n²) def select_sort(arr): """ 首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置. 再从剩余未排序元 ...
- 886C. Petya and Catacombs#墓室探险(set集合)
题目出处:http://codeforces.com/problemset/problem/886/C 题目大意:很多墓穴之间有通道,探险家来回穿梭并记录日志 日志规则:第一次到该墓穴计时间t,0&l ...
- 20199324《Linux内核原理与分析》第十一周作业
SET-UID程序漏洞实验 一.实验简介 Set-UID 是 Unix 系统中的一个重要的安全机制.当一个 Set-UID 程序运行的时候,它被假设为具有拥有者的权限.例如,如果程序的拥有者是root ...
- 1)PHP基础介绍
1.php基础介绍: Perssonal Home Page ====>PHP 2.应用范围 · web服务器脚本语言 命令行脚本语言 应用程序图形界面 3.PHP运行环境 PHP解释 ...
- 吴裕雄--天生自然 pythonTensorFlow自然语言处理:Attention模型--训练
import tensorflow as tf # 1.参数设置. # 假设输入数据已经转换成了单词编号的格式. SRC_TRAIN_DATA = "F:\\TensorFlowGoogle ...
- VS2010无法调试页面问题
图片: VS2010报:未能将脚本调试器附加到计算机XXX上的进程iexplore.exe . 已附加了一个调试器”.启动调试失败. 解决:1.以管理员身份打开CMD; 2.运行:regsvr32.e ...