[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 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:
e Explanation:
'e' is the letter that was added.
from collections import Counter
class Solution(object):
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
cs=Counter(s)
ct=Counter(t) for k in ct:
if cs[k]!=ct[k]:
return k
[LeetCode&Python] Problem 389. Find the Difference的更多相关文章
- [LeetCode&Python] Problem 530. Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
- [LeetCode&Python] Problem 594. Longest Harmonious Subsequence
We define a harmonious array is an array where the difference between its maximum value and its mini ...
- [LeetCode&Python] Problem 563. Binary Tree Tilt
Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the ab ...
- [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...
- [LeetCode&Python] Problem 492. Construct the Rectangle
For a web developer, it is very important to know how to design a web page's size. So, given a speci ...
- [LeetCode&Python] Problem 387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...
- [LeetCode&Python] Problem 783. Minimum Distance Between BST Nodes
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...
- [LeetCode&Python] Problem 427. Construct Quad Tree
We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...
- [LeetCode&Python] Problem 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
随机推荐
- Chargen UDP服务远程拒绝服务攻击漏洞修复教程
一.前置说明 chargen服务最初设计用于测试网络状态,监听19端口(包括TCP和UDP),其中UDP协议存在“Chargen UDP服务远程拒绝服务攻击漏洞”. chargen一般不会使用,所以直 ...
- nginx升级教程
1.说明 CVE-2016-4450,可通过构造特定数据包,可引发nginx引用空指针,导致nginx出错从而造成拒绝服务攻击. 影响1.3.9到1.11.0的所有版本,进行修复的1.10.1和1.1 ...
- Microsoft Windows远程桌面协议中间人攻击漏洞(CVE-2005-1794)漏洞解决方案(Windows server2003)
1.启动“终端服务配置” 2.选择“连接”,看到“RDP-Tcp”,在其上右键,选择“属性” 3.“常规”选项卡,将加密级别修改为“符合FIPS标准”,点击应用 应用即可,实验发现并不需要重启服务或操 ...
- MySQL设置白名单教程
1 登录mysql mysql -h host -u username -p password 2 切换至mysql库 use mysql; 3 查看当前允许登录IP及用户 select Host,U ...
- PyQt+Html+Js
先做记录,后面有时间在仔细研究 https://www.cnblogs.com/jiangjh5/p/7209315.html?utm_source=itdadao&utm_medium=re ...
- Win10系列:UWP界面布局基础2
属性设置 在面向对象程序开发中,所提及的属性通常指的是对象的属性.在XAML代码中,定义元素时也可以为其设置属性,例如对于一个TextBox元素,有背景属性.宽度属性和高度属性等.为了满足实际应用的需 ...
- nginx:负载均衡实战(一)
1.负载均衡说明 2.准备 我自己在电脑布置了两台虚拟机,两台都有nginx和tomcat,两台虚拟机布置的ip分别是37以及54,我在tomcat的首页动了点手脚,方便自己看是来自哪个ip的 接着在 ...
- day040 数据库索引补充 存储过程 事务等
1.正确使用索引 视图: 关键词 view 视图是体格虚拟表 创建视图 : create view 视图名称 as sql语句; 例: create view t_view as select * f ...
- JavaScrip(二)JavaScrip语法基础
一:标识符 标识符是指变量,函数的名字,或函数的参数名: 1.命名规则 1.1第一个字符必须是一个字母.下划线(_).或一个美元符号($) 1.2其他字母可以是字母,下划线.美元符号或数字 1.3不能 ...
- RabbitMQ 消息应答机制(message acknowledgments)
消息应答机制是一个很重要的功能,它能保证消息队列中的某个消息是否被成功处理.如果RabbitMQ server收到Consumer端发来的应答信号,就会将Consumer刚才处理的消息删除,并发送下一 ...