LeetCode38-countAndSay

递归:

        if( n == 1) return "1";
        String s = countAndSay(n-1);
        char[] c = s.toCharArray();
        int count = 1;
        String res = "";
        for(int i = 0; i < c.length-1; i++){
            if(c[i] == c[i+1]){
                count++;
            }
            else{
                res = res + count + c[i];
                count = 1;
            }
        }
        return res+count+c[c.length-1];

 

posted @ 2020-12-03 11:04  Amazon_Tina  阅读(65)  评论(0)    收藏  举报