---
# System prepended metadata

title: 1108. Defanging an IP Address
tags: [C++, LeetCode-Easy]

---

# 1108. Defanging an IP Address
Difficulty: Easy

## Solution

```cpp=
/**
*** Author: R-CO
*** E-mail: daniel1820kobe@gmail.com
*** Date: 2020-10-25
**/
#include <cstdlib>
#include <string>
using std::string;

class Solution {
 public:
  string defangIPaddr(string address) {
    static const string kDot{"."};
    auto dot_pos = address.find(kDot);
    while (dot_pos != string::npos) {
      static const string kReplaced{"[.]"};
      address.replace(dot_pos, 1, kReplaced);

      static const size_t kOffset = 3;
      dot_pos = address.find(".", dot_pos + kOffset);
    }

    return address;
  }
};

int main(int argc, char *argv[]) { return EXIT_SUCCESS; }

```

## Result

Success
Details 
Runtime: 0 ms, faster than 100.00% of C++ online submissions for Defanging an IP Address.
Memory Usage: 6.5 MB, less than 100.00% of C++ online submissions for Defanging an IP Address.

###### tags: `LeetCode-Easy` `C++`
