Meta Data#
Difficulty: easy First Attempt: 2022-10-18
- Submissions: Accepted (first try)
Approach#
Replace every . with [.], either with one replace or by building the result character by character in a list (String Template 1).
My Solution#
class Solution:
def defangIPaddr(self, address: str) -> str:
return address.replace(".", "[.]")
Complexity#
Time O(n), space O(n).
Mistakes to Avoid#
replacereturns a new string; the original is unchanged.
Interview Explanation#
I replace each dot with a bracketed dot in one replace call, in O(n).
