leetcode有效取消IP地址Leetcode轻松1108给定一个有效的(IPv4) IP地址,返回该IP地址的去角版本。去污点的IP地址会替换每个句点“.”为”[.]”。
class解决方案:
def defangIPaddr(self, address: str) -> str:
answerString = \"\"
for character in address:
if character == \".\":
answerString += \"[.]\"
else:
answerString += character
return answerString
暂无评论