leetcode1002
class Solution:
def commonChars(self, A: 'List[str]') -> 'List[str]':
n = len(A)
if n == 1:
return A
basestr = A[0]
baselist = {} for b in basestr:
if b not in baselist.keys():
baselist.update({b:1})
else:
baselist.update({b:baselist[b]+1})
for i in range(1,n):
cur = A[i]
curlist = {}
for c in cur:
if c not in curlist:
curlist.update({c:1})
else:
curlist.update({c:curlist[c]+1})
for d in baselist.keys():
if d not in curlist.keys():
baselist.update({d:0})
else:
baselist.update({d:min(baselist[d],curlist[d])})
result = list()
for e in baselist.keys():
for f in range(baselist[e]):
result.append(e) return result
leetcode1002的更多相关文章
- [Swift]LeetCode1002. 查找常用字符 | Find Common Characters
Given an array A of strings made only from lowercase letters, return a list of all characters that s ...
- LeetCode通关:哈希表六连,这个还真有点简单
精品刷题路线参考: https://github.com/youngyangyang04/leetcode-master https://github.com/chefyuan/algorithm-b ...
随机推荐
- Dubbo的原理以及详细原理、配置
Dubbo的背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. Dubbo的应用 用于大规模 ...
- ALGO-119_蓝桥杯_算法训练_寂寞的数
问题描述 道德经曰:一生二,二生三,三生万物. 对于任意正整数n,我们定义d(n)的值为为n加上组成n的各个数字的和.例如,d()=++=, d()=++++=. 因此,给定了任意一个n作为起点,你可 ...
- CentOS7切换到root用户和退回普通用户
切换成root用户: sudo su - 退出root用户并切换回普通用户: exit
- 【Spring学习笔记-2.1】Spring的设值注入和构造注入
设值注入: 先通过无参数的构造函数创建一个Bean实例,然后调用对应的setter方法注入依赖关系: 配置文件: <?xml version="1.0" encoding=& ...
- document.location.search 的作用
document.location.search 的作用 document.location.search 比如一个URL是XXXX?g=1,那么document.location.search的值就 ...
- jquery tr:even,tr:eq(),tr:nth-child()区别
jquery里面是不是搞不清楚,tr的选择器? $("tr:even"),$("tr:eq(2)"),$("tr:eq(3)"),$(&qu ...
- 控件之ReleLayout属性
Android:控件布局(相对布局)RelativeLayout RelativeLayout是相对布局控件:以控件之间相对位置或相对父容器位置进行排列. 相对布局常用属性: 子类控件相对子类控件:值 ...
- typescript泛型类 泛型方法
/* 泛型:软件工程中,我们不仅要创建一致的定义良好的API,同时也要考虑可重用性. 组件不仅能够支持当前的数据类型,同时也能支持未来的数据类型,这在创建大型系统时为你提供了十分灵活的功能. 在像C# ...
- 动态添加XtraTabControl的page页和子窗体
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...
- (转)Floyd算法
原文地址:http://www.cnblogs.com/twjcnblog/archive/2011/09/07/2170306.html 参考资料:http://developer.51cto.co ...