389. Find the Difference
来源:互联网 发布:摩尔软件安装 编辑:程序博客网 时间:2024/06/14 09:15
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:eExplanation:'e' is the letter that was added.class Solution(object):
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
letters={}
for c in s:
letters[c]=letters[c]+1 if c in letters else 1
for c in t:
if(c not in letters):
return c
letters[c]=letters[c]-1
if letters[c]<0:
return c
0 0
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference*
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- Search Graph Nodes
- 35. Search Insert Position
- redis 第一个hello world
- 写一个函数可以判断一个数是不是素数
- Mybatis关联查询一对一和一对多的实现
- 389. Find the Difference
- 16. 函数指针
- Android基础知识06
- Linux的进程------进程的描述和进程的创建
- KinectV2 在ubuntu14.04 环境下安装
- (M)SIM卡开机流程分析之默认APN设置
- 机器学习入门系列02,Regression 回归:案例研究
- 网站的海量数据和高并发的解决方案(一)
- mysql 数据库集群