Defanging an IP Address - LeetCode
Given a valid (IPv4) IP address
, return a defanged version of that IP address.
A defanged IP address replaces every period "."
with "[.]"
.
type conversion input string to list
if compiler finds '.', replace with '[.]'
type conversion back to string
"""
1108. Defanging an IP Address
Given a valid (IPv4) IP address, return a defanged version of that IP address.
A defanged IP address replaces every period "." with "[.]".
Input: address = "1.1.1.1"
Output: "1[.]1[.]1[.]1"
"""
address = list("1.1.1.1")
print(address)
i = 0
while i < len(address):
if address[i] == ".":
address.insert(i, "[.]")
address.remove(".")
i += 1
print(''.join(address))
in leetcode
How to convert list to string
''.join(list)
' '.join(list)