Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e82d35f

Browse files
Find Words That Can Be Formed by Characters
1 parent 84d6110 commit e82d35f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
""" https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/ """
2+
3+
class Solution:
4+
def countCharacters(self, words, chars):
5+
count = 0
6+
7+
for word in words:
8+
flag = True
9+
10+
for char in word:
11+
numberOfCharInChars = chars.count(char)
12+
numberOfCharInWord = word.count(char)
13+
14+
if (numberOfCharInWord > numberOfCharInChars):
15+
flag = False
16+
break
17+
else:
18+
index = chars.find(char)
19+
20+
if (index == -1):
21+
flag = False
22+
break
23+
24+
if (flag == True):
25+
count += len(word)
26+
27+
return count
28+
29+
print(Solution().countCharacters(["hello","world","leetcode"], "welldonehoneyr"))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /