From ff727968bca56fd764b6a381179954e85a3b5722 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Sun, 15 Oct 2023 10:27:39 +0530 Subject: [PATCH] Update uncompress-string_en.md Added JS solution for the problem --- problem/uncompress-string_en.md | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/problem/uncompress-string_en.md b/problem/uncompress-string_en.md index 054a1e7a..ad471184 100644 --- a/problem/uncompress-string_en.md +++ b/problem/uncompress-string_en.md @@ -1,4 +1,29 @@ - -There is no solution yet. - -Would you like to [contribute to the solution](https://github.com/BFEdev/BFE.dev-solutions/blob/main/problem/uncompress-string_en.md)? [Contribute guideline](https://github.com/BFEdev/BFE.dev-solutions#how-to-contribute) +function uncompress(str) { + let curNum=0, curStr='',stack=[] + for(let i=0;i0 && !isNaN(parseInt(str[i-1]))){ + curNum = curNum*10+parseInt(str[i]) + } else { + curNum=parseInt(str[i]) + } + } + //If it is opening brancket + else if(str[i]==='('){ + stack.push({curNum,curStr}); + curNum=0; + curStr='' + } + //If it is closing brancket + else if(str[i]===')'){ + let element = stack.pop(); + curStr = element.curStr + curStr.repeat(element.curNum) + } + //If it is alphabets + else { + curStr+=str[i] + } + } + return curStr +}