[leetcode] 530. Minimum Absolute Difference in BST
745
2022-08-23
[leetcode] 1108. Defanging an IP address
Description
Given a valid (IPv4) IP address, return a defanged version of that IP address.
A defanged IP address replaces every period “.” with “[.]”.
Example 1:
Input: address = "1.1.1.1"Output: "1[.]1[.]1[.]1"
Example 2:
Input: address = "255.100.50.0"Output: "255[.]100[.]50[.]0"
Constraints:
The given address is a valid IPv4 address.
分析
题目的意思是:把IP地址‘.’替换成’[.]’,实现也很直接,直接遍历,把相应的位置变换一下就可以了哈。
代码
class Solution: def defangIPaddr(self, address: str) -> str: res='' for ch in address: if(ch!='.'): res+=ch else: res+='[.]' return res
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~