Input: 1 Output:"1" Expected:"1", Why cannot go through the test case?


  • 0
    K
    class Solution {
    public:
        string countAndSay(int n) {
            if(n<=0)
                return "";
            string str="1";
            string tmp="";
            for(int i=0; i<n; i++){
                int idx=0, cnt=0;
                char ch; 
                while(idx<str.size()){
                    ch=str[idx];
                    cnt=0;
                    while(str[idx]==ch){
                        cnt++;
                        idx++;
                    }
                    tmp+=cnt;
                    tmp+=ch;
                }
                str=tmp;
                tmp.clear();
            } 
            return str;
        }
    };
    
    
    
    Submission Result: Wrong Answer
    
    Input:	1
    Output:	"1"
    Expected:	"1"

Log in to reply
 

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