hugo-blog/content/posts/2020-04-01-leetcode-1160.md
Ching 5ba7024532 feat(content; layouts; static): migrate hexo blog. add new theme fuji.
migrate hexo blog. add new theme fuji.

Signed-off-by: Ching <loooching@gmail.com>
2022-02-07 23:38:40 +08:00

40 lines
607 B
Markdown

---
title: leetcode-1160
date: 2020-04-01 00:18:48
tags:
- leetcode
categories: leetcode
---
### 1160. 拼写单词
[题目](https://leetcode-cn.com/problems/find-words-that-can-be-formed-by-characters/)
<!--more-->
利用列表 remove 方法,检查 chars 中是否有足够的字母拼写 word
```python
class Solution:
def countCharacters(self, words, chars: str) -> int:
words_ = ''
for w in words:
lchars = list(chars)
try:
for l in w:
lchars.remove(l)
except:
continue
words_ += w
return len(words_)
# 152 ms 14.1 MB
```