leetcode1160

Posted asenyang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode1160相关的知识,希望对你有一定的参考价值。

 1 class Solution:
 2     def countCharacters(self, words: List[str], chars: str) -> int:
 3         n = len(chars)
 4         m = len(words)
 5         if n == 0 or m == 0:
 6             return 0
 7         dic = 
 8         
 9         for i in range(n):
10             if chars[i] not in dic:
11                 dic[chars[i]] = 1
12             else:
13                 dic[chars[i]] += 1
14         sums = 0
15         
16         for i in range(m):
17             temp = dic.copy()
18             cur = words[i]
19             k = 0
20             for j in range(len(cur)):
21                 c = cur[j]
22                 if c in temp and temp[c] > 0:
23                     temp[c] -= 1
24                     k += 1
25             if k == len(cur):
26                 sums += len(cur)
27         return sums
28             
29             

算法思路:hash表。

以上是关于leetcode1160的主要内容,如果未能解决你的问题,请参考以下文章

拼写单词(leetcode 1160)

拼写单词(leetcode 1160)

LeetCode --- 1160. Find Words That Can Be Formed by Characters 解题报告

LeetCode --- 1160. Find Words That Can Be Formed by Characters 解题报告

Leetcode 1160. Find Words That Can Be Formed by Characters

LeetCode 解题目录汇总