题目1
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c0bb220ea86388511ab8a74248fda99b.png)
题解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
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/696ff96ec0cf28b260fa03ccf5bc6c5c.png)
题解2
class Solution:
def defangIPaddr(self, address: str) -> str:
address = address.replace('.', '[.]')
return address
题目3
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/83139a7594ba85dce05173f71fcb1e57.png)
题解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链接