? 38. 报数-LeetCode

心得:效果不理想,后期还会改进

 1 class Solution {
 2     public String countAndSay(int n) {
 3             String str="1";
 4             for(int i=2;i<=n;i++)
 5             {
 6                 char[] s=String.valueOf(str).toCharArray();
 7                      str="";
 8                     int index=1;
 9                   for(int j=0;j<s.length;j++)
10                 {
11                     if(j+1<s.length&&s[j]==s[j+1])
12                         index++;
13                     else
14                     {
15                         str=str+index+s[j];
16                         index=1;
17                     }
18                 }
19             }
20             return  str;
21         }
22 }

猜你喜欢

转载自www.cnblogs.com/pc-m/p/10936445.html