标签:log generate ber valueof else build leetcode member tin
class Solution { public String countAndSay(int n) { if (n == 0) { return "0"; } String result = "1"; for (int i = 1; i < n; i++) { result = generateCount(result); } return result; } private String generateCount(String current) { int count = 1; char currentC = current.charAt(0); StringBuilder result = new StringBuilder(); for (int i = 1; i < current.length(); i++) { if (currentC != current.charAt(i)) { result.append(String.valueOf(count)); result.append(currentC); currentC = current.charAt(i); count = 1; } else { count++; } } result.append(String.valueOf(count)); result.append(currentC); return result.toString(); } }
1. Remember to add it again after counting since there are still remaining information in cache.
标签:log generate ber valueof else build leetcode member tin
原文地址:http://www.cnblogs.com/shuashuashua/p/7417790.html