码迷,mamicode.com
首页 > 其他好文 > 详细

? 38. 报数-LeetCode

时间:2019-05-28 12:24:45      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:mamicode   solution   leetcode   info   i++   col   turn   valueof   改进   

技术图片

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

 

 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 }

 

? 38. 报数-LeetCode

标签:mamicode   solution   leetcode   info   i++   col   turn   valueof   改进   

原文地址:https://www.cnblogs.com/pc-m/p/10936445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!