Under my umbrella.

SKII

Less is more.

力扣题解 38th 外观数列

38th 外观数列

  • 简单模拟

    根据题目描述,简单的模拟一遍即可。

    class Solution {
        public String countAndSay(int n) {
            StringBuilder sb = new StringBuilder("1");
    
            for (int k = 1; k < n; k++) {
                StringBuilder temp = new StringBuilder();
                int i = 0, j = 0;
    
                while (i < sb.length()) {
    
                    while (j < sb.length()) {
                        if (sb.charAt(i) != sb.charAt(j)) break;
                        j++;
                    }
    
                    temp.append(j - i);
                    temp.append(sb.charAt(i));
    
                    i = j;
                }
    
                sb = temp;
            }
    
            return sb.toString();
        }
    }
    
posted @ 2020-07-06 15:32  NLYang  阅读(126)  评论(0编辑  收藏  举报