Skip to content

Commit 08ecd43

Browse files
committed
做了道题
1 parent 2d2ea81 commit 08ecd43

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

main.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,32 @@ def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]:
297297
ans.append(word_temps[temp])
298298
return ans
299299

300-
def maximumHappinessSum(self, happiness: List[int], k: int) -> int:
301-
hp = []
302-
for h in happiness:
303-
heapq.heappush(hp, -h)
300+
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
301+
words = text.split()
302+
mp = defaultdict(int)
303+
for char in brokenLetters:
304+
mp[char] = 1
304305
ans = 0
305-
for i in range(k):
306-
temp = heapq.heappop(hp)
307-
if -temp - i> 0:
308-
ans += -temp - i
309-
else:
310-
break
306+
for word in words:
307+
flag = 1
308+
for char in word:
309+
if mp[char] == 1:
310+
flag = 0
311+
break
312+
ans += flag
311313
return ans
314+
315+
def digitSum(self, s: str, k: int) -> str:
316+
while len(s) > k:
317+
op = 0
318+
temp = ""
319+
while op < len(s):
320+
chunk = s[op:min(len(s), op+k)]
321+
op += k
322+
chunk = str(sum([int(i) for i in chunk]))
323+
temp += chunk
324+
s = temp
325+
return s
312326
s = Solution()
313327
print(s.minCost(maxTime = 29, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3]))
314328

0 commit comments

Comments
 (0)