[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 ...
随机推荐
- Angular4.x 引入第三方 JS
引入 Jquery 使用 angular-cli 新建 angular项目 1.安装 jquery npm install jquery --save 2..angular-cli.json 中引入 ...
- Mysql可重复读原理
mysql可重复读现象及原理分析 InnoDB---可重复读隔离级别的底层实现原理 概念 可重复读的实现 Repeatable Read(可重复读):一个事务在执行过程中可以看到其他事务已经提交的新插 ...
- ActiveMQ broker 非持久化queue消息的入队、出队和应答
消息入队:Queue.doMessageSend 消息分发:Queue.doActualDispatch 消息发送:TransportConnection.dispatch broker收到consu ...
- Struts 2 初步入门(三)
接Struts 2初步入门(二) 若想用多个通配符设定访问: <struts> <package name="default" namespace="/ ...
- oracle中计算两个日期的相差天数、月数、年数、小时数、分钟数、秒数等
oracle如何计算两个日期的相差天数.月数.年数.小时数.分钟数.秒数 1.相差天数(两个日期相减) --Oracle中两个日期相差天数-- select TO_NUMBER(TO_DATE('20 ...
- Java中数据类型相互转化
1 将String 转换成int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([String], ...
- PC/FORTH 数字类型
body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...
- Linux 目录配置标准:FHS
目录 应放置内容 /bin 和/user/目录下的/bin/都是用来保存的系统命令 /sbin 和/user/目录下的/sbin是用来保存root的系统命令 /boot 这个目录主要放置开机所用的文件 ...
- Docker小白从零入门到实战系列【二】
1.安装好Centos 7 2.关闭SELINUX sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/configsetenfo ...
- heightchart配置详解
<div id="container" style="width: 100%; margin: 0 auto"></div><sc ...