标签:and 技术 nta builder for ring load ima int
这到题一开始自己想到的是用两个栈来转换,再用一个lis来存储。。。经过验证这也太麻烦了
看了大佬的解答,可以直接用stringbuilder来存储
package leetcode;/** * @author doyinana * @create 2020-07-21 18:05 */ public class L38 { public String countAndSay(int n) { String str="1"; for(int i = 2;i<=n;i++){ StringBuilder builder = new StringBuilder(); char pre = str.charAt(0); int count=1; for(int j=1;j<str.length();j++){ char c = str.charAt(j); if(c==pre){ count++; }else{ builder.append(count).append(pre); pre=c; count=1; } } builder.append(count).append(pre); str=builder.toString(); } return str; } }
标签:and 技术 nta builder for ring load ima int
原文地址:https://www.cnblogs.com/doyi111/p/13358789.html