# 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++`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up