classSolution{public:stringdecodeAtIndex(strings,intk){longsize=0;// Length of decoded `s`for(constcharc:s)if(isdigit(c))size*=c-'0';else++size;for(inti=s.length()-1;i>=0;--i){k%=size;if(k==0&&isalpha(s[i]))returnstring(1,s[i]);if(isdigit(s[i]))size/=s[i]-'0';else--size;}throw;}};
classSolution{publicStringdecodeAtIndex(Strings,intk){longsize=0;// Length of decoded `s`for(finalcharc:s.toCharArray())if(Character.isDigit(c))size*=c-'0';else++size;for(inti=s.length()-1;i>=0;--i){k%=size;if(k==0&&Character.isAlphabetic(s.charAt(i)))returns.substring(i,i+1);if(Character.isDigit(s.charAt(i)))size/=s.charAt(i)-'0';else--size;}thrownewIllegalArgumentException();}}