LeetCode solutions

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

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 3ms, memory 7.5MB, accepted 2025-12-28.

cpp
class Solution {
public:
    string defangIPaddr(string address) {
        string result;
        for (char c : address) {
            if (c == '.') result += "[.]";
            else result += c;
        }
        return result;
    }
};

Source