Easy C++ solution with O(n^2) time complexity


#1
string Solution::countAndSay(int A) 
{
    string s="1";
    int count=1;
    while(count<A)
    {
        string tmp="";
        int i=0,n=s.length();
        while(i<n)
        {
            int j=i,quantity=0;
            while(i<n && s[i]==s[j])
            {
                quantity++;
                i++;
            }
            tmp+=to_string(quantity);
            tmp.push_back(s[j]);
        }
        s=tmp;
        count++;
    }
    return s;
}


#2

I guess the time complexity is O(2^k). Since the length of the k+1th step string will at most be double of the kth step string. Hence sum of the geometric progression will give O(2^k) complexity. Correct me if am wrong.