Count and Say

来源:互联网 发布:mac 批量转换cr2 编辑:程序博客网 时间:2024/05/07 02:29

Notes: Before you understand the questions, you shouldn't start to code!

public class Solution {    public String countAndSay(int n) {        String seqString = "1";                    if(1 == n){          return seqString;          }          String tmpString;          for(int i = 2; i <= n; i++){          tmpString = "";          int cnt = 1, j;                  for(j = 1; j < seqString.length(); j++){          if (seqString.charAt(j) == seqString.charAt(j - 1)) {cnt++;          }          else {tmpString += cnt + "" + seqString.charAt(j-1);cnt = 1;          }          }    tmpString += cnt + "" + seqString.charAt(j-1);                   seqString = tmpString;          }                    return seqString;    }}


0 0