Find the Difference --LeetCode
来源:互联网 发布:天猫魔盒网络无法连接 编辑:程序博客网 时间:2024/05/18 13:05
Find the Difference
Difficulty: Easy
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.
用到collection模块的Counter: 计数器,主要用来计数
实现:
class Solution(object): def findTheDifference(self, s, t): """ :type s: str :type t: str :rtype: str """ ds = collections.Counter(s) dt = collections.Counter(t) return (dt - ds).keys().pop() #*counter返回一个字典,dt减去ds去掉重合的部分字符*
0 0
- Leetcode:Find the Difference
- Find the Difference --LeetCode
- LeetCode Find the Difference
- [LeetCode] Find the Difference
- [Leetcode] Find the Difference
- [Leetcode] Find the Difference
- [Leetcode]Find the Difference
- [LeetCode]Find the Difference
- LEETCODE--Find the Difference
- LeetCode:Find the Difference
- LeetCode Find the Difference
- Find the Difference(leetcode)
- LeetCode : 389. Find the Difference
- LeetCode 389 Find the Difference
- Leetcode 389. Find the Difference
- leetcode之Find the Difference
- 【leetcode】389. Find the Difference
- Leetcode 389 Find the Difference
- 怎样从user版本中提取应用数据
- new和malloc
- php下ftp扩展安装
- Python 代码获取对应的网址
- YARN的内存和CPU配置
- Find the Difference --LeetCode
- nginx+keepalived高可用及双主模式
- vs2010未能正确加载XX包的解决方法
- vtkFeatureEdges 类简介
- Ubuntu Sublime test3不能输入中文的解决办法
- centos7配置nginx负载均衡
- 对异常检查的思考
- 添加了.gitignore对文件无效
- 什么样的RPC才是好用的RPC