1205. Defanging an IP Address
My accepted C++ solution to LeetCode problem 1205, Defanging an IP Address, running in 3ms.
- Difficulty: Easy
- C++
- Runtime 3ms
- Memory 7.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 3ms, memory 7.5MB, accepted 2025-12-28.
class Solution {
public:
string defangIPaddr(string address) {
string result;
for (char c : address) {
if (c == '.') result += "[.]";
else result += c;
}
return result;
}
};