1.力扣394--字符串解码
class Solution { public String res; public int i; public String decodeString(String s) { res = new String(); int n = s.length(); i = 0; for(;i<n;i++){ int k = s.charAt(i) - '0'; //System.out.println(k); if(k>=1&&k<=9){ int num = k; i++; while(s.charAt(i)-'0'>=0&&s.charAt(i)-'0'<=9){ num = num*10+(s.charAt(i)-'0'); i++; } //System.out.println(num); res += dfs(s,num); }else{ res += s.charAt(i); } } return res; } public String dfs(String s,int k){ String temp = new String(); i++; while(i<s.length()){ int kk = s.charAt(i) - '0'; //System.out.println(s.charAt(t)); if(kk>=1&&kk<=9){ int num = kk; i++; while(s.charAt(i)-'0'>=0&&s.charAt(i)-'0'<=9){ num = num*10+(s.charAt(i)-'0'); i++; } //System.out.println(num); temp += dfs(s,num); }else if(s.charAt(i) == ']'){ String cur = new String(); for(int p = 0;p<k;p++){ cur += temp; //System.out.println(temp); } //System.out.println(k); return cur; }else{ temp += s.charAt(i); //System.out.println(temp); } i++; } return temp; } }
标签:27,String,--,int,2023.1,&&,public From: https://www.cnblogs.com/lyjps/p/17069880.html