LC 1108. Defanging an IP Address

Nilanjan Deb · April 5, 2020

This is my CPP solution.

class Solution {
public:
    string defangIPaddr(string address) {
        string res;
        int i = 0;
        for(int i=0;i<address.size();i++){
            if(address[i] == '.'){
                res += "[.]";
            }
            else{
                res.push_back(address[i]);
            }
        }
        return res;
    }
};


Dicussion Forum