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 ...
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 =10Output:"o"Explanation:The decodedstringis"leetleetcodeleetleetcodeleetleetcode". The10th letterinthestringis"o". Example 2: Input:S...
例如leet2code3可看为(leet*2,code)*3,K为10时,l为36,36/3 = 12,K%12 = 10,10比8(leetleet)长,那么直接返回10 - 8 = 2,即o。 classSolution{ public: stringdecodeAtIndex(stringS,intK) { stringans; strings; longl=0; vector<pair<string,int>>seg; for(inti=0;i<S.length();i++) ...
Now for some encoded stringS, and an indexK, find and return theK-th letter (1 indexed) in the decoded string. Example 1: AI检测代码解析 Input: S = "leet2code3", K = 10 Output: "o" Explanation: The decoded string is "leetleetcodeleetleetcodeleetleetcode". The 10th letter in the...
class Solution { public: string decodeAtIndex(string S, int K) { long size = 0; // 要用long,如果用int会数据溢出 int i = 0; for (i = 0; i < S.size(); i++) { if (!isdigit(S[i])) size++; else size *= S[i] - '0'; if (size >= K) break; } if (i == S.si...
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>=...
例如leet2code3可看为(leet*2,code)*3,K为10时,l为36,36/3 = 12,K%12 = 10,10比8(leetleet)长,那么直接返回10 - 8 = 2,即o。 class Solution { public: string decodeAtIndex(string S, int K) { string ans; string s; long l = 0; vector<pair<string, int>> seg; for (int i ...
/** 1602 · Decoded String at Index Algorithms Medium Accepted Rate 56% DescriptionSolutionNotesDiscussLeaderboard Description An encoded string S is given. To find and write the decoded string ...leetcode 884. Decoded String at Indexd题解法 题目大意是给出编码之后的字符串,求解码后的字符串的指...