How to share my code :I think my way is easy and good


  • 0
    E

    public class Solution {
    public String countAndSay(int n) {
    int t=n-1;
    StringBuffer str=new StringBuffer();
    String s=String.valueOf(1);
    while(t-->0){

              char []tmp=s.toCharArray();
              for(int i=0;i<s.length();i++){
                  int cnt=1;
                  while(i+1<s.length()&&tmp[i]==tmp[i+1]){i++;cnt++;}
                  str.append(cnt);
                  str.append(tmp[i]);
              }
             s=str.toString();
             str.delete(0, str.length());
          }
          return s;
    }
    

    }


  • 0

    You can use markdown to properly format your code. I believe they use similar markdown syntax as that in stackoverflow: editing help


Log in to reply
 

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