1 Star 3 Fork 5

刘炜/python LeetCode

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1160拼写单词.py 782 Bytes
一键复制 编辑 原始数据 按行查看 历史
刘炜 提交于 2020-03-17 15:08 +08:00 . 哈希表
class Solution:
def countCharacters(self, words: List[str], chars: str) -> int:
chardict = {}
rlt = 0
for char in chars:
if char in chardict.keys():
chardict[char] += 1
else:
chardict[char] = 1
for word in words:
wdict = {}
iscontain = True
for char in word:
if char in wdict.keys() and char in chardict.keys() and wdict[char] < chardict[char]:
wdict[char] += 1
elif char not in wdict.keys() and char in chardict.keys():
wdict[char] = 1
else:
iscontain = False
if iscontain == True:
rlt += len(word)
return rlt
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/new_way/python-LeetCode.git
git@gitee.com:new_way/python-LeetCode.git
new_way
python-LeetCode
python LeetCode
master

搜索帮助