[220207] Find the Difference
You are given two strings
s
andt
.String
t
is generated by random shuffling strings
and then add one more letter at a random position.Return the letter that was added to
t
.
class Solution:def findTheDifference(self, s, t):c = 0for char in t:# 使用 ASCII 码记录c ^= ord(char)# ^ 计算,抵消相同数字 (x ^ x == 0)for char in s:c ^= ord(char)return chr(c)
from collections import Counterclass Solution:def findTheDifference(self, s, t):c_s = Counter(s)c_t = Counter(t)for item in c_t:# 分别比较每个字母出现的次数if not c_t[item] == c_s[item]:return item
[220207] Find the Difference相关推荐
- ADPRL - 近似动态规划和强化学习 - Note 10 - 蒙特卡洛法和时序差分学习及其实例 (Monte Carlo and Temporal Difference)
Note 10 蒙特卡洛法和时序差分学习 Monte Carlo and Temporal Difference 蒙特卡洛法和时序差分学习 Note 10 蒙特卡洛法和时序差分学习 Monte Car ...
- Linux: what's the difference between /proc/self and /proc/$$?
我在Stack Overflow上提了一个问题:linux - what's the difference between /proc/self and /proc/$$? - Stack Overf ...
- python 集合set 的三大方法intersection union difference来处理文氏图
TODO - 练习:A或B,但不能同时包含 编写一个函数,将两个集合(set_a和set_b)作为输入,并返回一个新的集合,其中包含set_a或set_b中的元素,但不包含两者兼有的元素. 在上面的文 ...
- Difference between prop and attr in different version of jquery
jQuery <1.9 $('#inputId').attr('readonly', true); jQuery 1.9+ $('#inputId').prop('readonly', true ...
- What’s the Difference between a Hue, Tint, Shade and Tone ?
What's the Difference between a Hue, Tint, Shade and Tone ? Ask Yourself first- What's the differenc ...
- G面经prepare: Set Intersection Set Difference
求两个sorted数组的intersection e.g. [1,2,3,4,5],[2,4,6] 结果是[2,4] difference 类似merge, 分小于等于大于三种情况,然后时间O(m+n ...
- LeetCode——Find the Difference
LeetCode--Find the Difference Question Given two strings s and t which consist of only lowercase let ...
- python 并集union, 交集intersection, 差集difference, 对称差集symmetric_difference
python的集合set和其他语言类似,是一个无序不重复元素集, 可用于消除重复元素. 支持union(联合), intersection(交), difference(差)和sysmmetric d ...
- 理解一条语句:SELECT difference(sum(value)) FROM mq_enqueue WHERE channel =~ /ActiveMQ_TEST/ AND $tim...
最近使用grafana在查询InfluxDB中,用到了这一条语句 SELECT difference(sum("value")) FROM "mq_enqueue&quo ...
最新文章
- [Struts]Cannot find bean in any scope之一解
- libtorchWindows中的使用
- opencv打开摄像头采集和保存
- java8返回单个号码_如何在单个API中支持Java 6、8、9
- jQuery中绑定事件的几种方法
- php 批量删除挂马文件夹,PHP批量挂马脚本
- 漫画小程序支持流量主更新修复接口,自动采集资源,漫画源码漫画小程序源码简单即可发布
- 软件工程导论复习之总体设计
- 广州的11个辖区_13张地形图,快速了解广东省广州市的11个市辖区
- python题目-兔子生育计数
- 微信小程序企业号注册
- 「又报错了TAT」 编译器报错是什么原因error: lvalue required as left operand of assignment|
- [乡土民间故事_徐苟三传奇]第七回_赵财主之母配孟德
- 焦虑症和抑郁症有什么区别吗?
- 【mac】nvm 的安装和使用,解决mac重启node not found,每次都得source ~/.bash_profile
- Android PC同步软件 类似 apple 的 itunes
- 精选Java必看200道面试题
- 华为云-文字识别OCR-身份证识别
- [通信原理实验]北京邮电大学信息工程专业
- 一份超详细的Java问题排查工具单