1classSolution {2publicString decodeAtIndex(String S,intK) {3longsize = 0;4intn =S.length();56//find size = length of decoded string7for(inti = 0; i < n; i++) {8charc =S.charAt(i);9if(Character.isDigit(c)) {10size *= c - '0';11}else{12size++;13}14}1516for(inti ...
参考[LeetCode] 880. Decoded String at Index 在位置坐标处解码字符串。 代码实现 Java classSolution{publicStringdecodeAtIndex(String S,intK){longsize=0;intindex=0;while(index < S.length() && size < K) {charc=S.charAt(index); size = Character.isDigit(c) ? size * (c -'0') : size ...
Now for some encoded stringS, and an indexK, find and return theK-th letter (1 indexed) in the decoded string. Example 1: Input: S = "leet2code3", K = 10 Output: "o" Explanation: The decoded string is "leetleetcodeleetleetcodeleetleetcode". The 10th letter in the string is "o...
classSolution{public:stringdecodeAtIndex(stringS,intK){long size=0;// 要用long,如果用int会数据溢出int i=0;for(i=0;i<S.size();i++){if(!isdigit(S[i]))size++;elsesize*=S[i]-'0';if(size>=K)break;}if(i==S.size())// for循环时要注意越界问题i=S.size()-1;for(int j=i;j...
916-decoded-string-at-index/README.md +48 Original file line numberDiff line numberDiff line change @@ -0,0 +1,48 @@ 1 + <h2><a href="https://leetcode.com/problems/decoded-string-at-index">Decoded String at Index</a></h2> <img src='https://img.shields.io/badge/Difficul...
DecodedStringAtIndex.java ExcelSheetColumnTitle.java GlobalAndLocalInversions.java LargestComponentSizebyCommonFactor.java MinimumIndexSumOfTwoLists.java NthDigit.java NthMagicalNumber.java ProjectionAreaOf3DShapes.java RangeAdditionII.java ReachingPoints.java ...
classSolution{public:stringdecodeAtIndex(string S,intK){longsize=0;// 要用long,如果用int会数据溢出inti=0;for(i=0;i<S.size();i++){if(!isdigit(S[i]))size++;elsesize*=S[i]-'0';if(size>=K)break;}if(i==S.size())// for循环时要注意越界问题i=S.size()-1;for(intj=i;j>=...
classSolution{ public: string decodeAtIndex(stringS,intK) { long cnt = 0; for (inti= 0;i<S.size(); ++i) { if (isalpha(S[i])) { if (++cnt==K) return string(1,S[i]); } else { if (cnt* (S[i] - '0') >=K) return decodeAtIndex(S.substr(0,i), (K- 1) % cnt...
1classSolution {2func decodeAtIndex(_ S: String, _ K: Int) ->String {3varstack: [Character] =[]45varcharCount: Int =06varmovingIndex: Int =07varS =Array(S)89whilemovingIndex < S.count && charCount <K {10let character =S[movingIndex]11ifcharacter.isDigit() {12charCount *=characte...