Meta tags:
description= Given an encoded string, return its decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brac...;
keywords= leetcode, javascript, solutions, algorithms, data structures, coding, programming, coding challenges, coding problems, coding solutions;
author= LeetCodeJavascript.com;
Headings (most frequently used words):
394, decode, string, problem, description, solution,
Text of the page (most frequently used words):
#string (8), the (8), result (7), decoder (5), that (5), stack (4), are (4), return (3), const (3), for (3), number (3), else (3), leetcodejavascript (2), com (2), let (2), previous (2), count (2), repeat (2), will (2), there (2), not (2), input (2), you (2), may (2), assume (2), square (2), brackets (2), digits (2), encoded_string (2), view (2), github (2), leetcode (2), 394 (2), decode (2), solutions (2), 2025, josh, crozier, param, var, decodestring, function, isnan, push, pop, solution, test, cases, generated, length, output, never, exceed, 105, example, like, always, valid, extra, white, spaces, well, formed, etc, furthermore, original, data, does, contain, any, and, only, those, numbers, encoding, rule, where, inside, being, repeated, exactly, times, note, guaranteed, positive, integer, given, encoded, its, decoded, problem, description, recursion, medium, back, all, star, javascript,
Text of the page (random words):
394 decode string leetcode javascript solutions leetcodejavascript com star on github back to all solutions 394 decode string medium view on leetcode view on github string stack recursion problem description given an encoded string return its decoded string the encoding rule is k encoded_string where the encoded_string inside the square brackets is being repeated exactly k times note that k is guaranteed to be a positive integer you may assume that the input string is always valid there are no extra white spaces square brackets are well formed etc furthermore you may assume that the original data does not contain any digits and that digits are only for those repeat numbers k for example there will not be input like 3a or 2 4 the test cases are generated so that the length of the output will never exceed 105 solution param string s return string var decodestring function s const stack let result let decoder 0 for const c of s if isnan c number c 0 number c 9 decoder number c decoder 10 else if c stack push result decoder result decoder 0 else if c const previous count stack pop result previous result repeat count else result c return result 2025 leetcodejavascript com josh crozier
|