题目1
题解1
from queue import PriorityQueue
class Solution:
def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
pq = PriorityQueue(maxsize=0)
for c in "!?',;.":
paragraph= paragraph.replace(c, ' ')
paragraph = paragraph.lower().split()
paragraph_set = set(paragraph)
for num in paragraph_set:
pq.put((-(paragraph.count(num)),num))
while pq:
temp = pq.get()
if temp[1] not in banned:
return temp[1]
题目2
题解2
class Solution:
def defangIPaddr(self, address: str) -> str:
address = address.replace('.', '[.]')
return address
题目3
题解3
class Solution:
def canJump(self, nums: List[int]) -> bool:
index = 0
max_dist = 1
while index < max_dist:
max_dist = max(max_dist, index+nums[index]+1)
if max_dist>=len(nums):
return True
index += 1
return False
附上题目链接:
题目1链接
题目2链接
题目3链接