My personal solution about this problem


  • 0
    H
    public String countAndSay(int n) {
           if(n == 1)
                return "1";
            String initString = countAndSay(n-1);
            String resultString = "";
            int count=1;
            for(int i = 1 ; i< initString.length();i++){
                if(initString.charAt(i)==initString.charAt(i-1)){
                    count++;
                    continue;
                }else{
                    resultString= resultString+count+initString.charAt(i-1);
                    count=1;
                }
            }      
            resultString = resultString+count+initString.charAt(initString.length()-1);
            return resultString;
        }
    

    my personal solution


Log in to reply
 

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