Any one has solution with less boundary cases?


  • 1
    N
    void Call_Me(string st, string s, int i , int dot ,int l , vector<string >&ans )
    
    {   if(i==l && dot==4)
           {
               st.pop_back();
               ans.push_back(st);
           }
           if(i>=l || dot>=4) return ;
    
           Call_Me(st+s.substr(i,1)+"." , s, i+1 ,dot+1, l,ans);
    
                if(s[i]=='0')   
                        return ;
    
           Call_Me(st+s.substr(i,2)+".", s, i+2 , dot+1, l ,ans);
    
           if(s[i]=='1' || s[i]=='2' && (s[i+1]<='4' || (s[i+1]=='5' && s[i+2]<='5')))
    
           Call_Me(st+s.substr(i,3)+"." , s, i+3 , dot+1, l ,ans);
     }
        vector<string> restoreIpAddresses(string s) {
    
            string st="";
            vector<string>ans;
            int dot=0,l;
            l=s.size();
            s=s+"000";
    
            Call_Me(st , s, 0, dot , l,  ans);
    
            return ans;
        }

  • 0
    N
    This post is deleted!

  • 0
    S

    Pay attention to "Writing code? Select all code then click on the {} button to preserve code formatting.” above text editor.


  • 1
    N
    This post is deleted!

  • 0
    S

    Thanks for your post. However it would be better to share solution with correct code format and elaborated thoughts. Please read the Discuss FAQ for more info.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.