LeetCode #394 - Decode String

题目描述:

Given an encoded string, return it's 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; 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 won't be input like 3a or 2[4].

Examples:

s = "3[a]2[bc]", return "aaabcbc".
s = "3[a2[c]]", return "accaccacc".
s = "2[abc]3[cd]ef", return "abcabccdcdcdef".


用栈储存“[”前面的数字和字母字符串,遍历到数字或者字母就不断累加,当遍历到“[”就压栈,遍历到“]”就出栈,并根据出栈的数字和字母字符串做倍增和相加操作。

class Solution {
public:
    string decodeString(string s) {
        stack<string> str;
        stack<int> k;
        string result;
        int count=0;
        for(int i=0;i<s.length();i++)
        {
            if((s[i]<='z'&&s[i]>='a')||(s[i]>='A'&&s[i]<='Z')) result+=s[i];
            else if(s[i]>='0'&&s[i]<='9')
            {
                count*=10;
                count+=s[i]-'0';
            }
            else if(s[i]=='[')
            {
                k.push(count);
                count=0;
                str.push(result);
                result="";
            }
            else if(s[i]==']')
            {
                int times=k.top();
                k.pop();
                for(int j=0;j<times;j++) str.top()+=result;
                result=str.top();
                str.pop();
            }
        }
        return result;
    }
};

EEGLAB数据预处理基本流程GUI实操指南 按钮,会出现如上图所示的长条形对话框,方框里面是所有电极的名称,这时将需要的剔除的电极选择上,如上图,我选择了 VEOG这个电极(该电极表示是垂直眼电),然后点“OK”,在弹出的对话框中自行确定是否需要修改命名。坏导是指在数据采集时,由于各种原因(如,电极本身问题或阻抗不好等)导致数据记录有问题,但是在后期又特别想要该通道的数据,那么就可以利用插值的方法进行——利用该导联周边的几个电极点的均值作为该导的数据。上图的图是通过IClabel的工具箱进行自动判断的,可以帮助自动识别出哪些是Eye的成分。 阅读详情

相关推荐

避开RK3588开发板SDIO配置的坑:O9201SB WiFi模组接入实战指南

本文为嵌入式开发者提供了在RK3588开发板上,利用TF卡槽接入O9201SB WiFi6模组的实战指南。文章深度剖析了SDIO配置中常见的电源管理序列冲突问题,并给出了从设备树节点修改、内核编译到系统验证的完整解决方案,帮助开发者避开配置陷阱,成功实现高性能无线连接。

sprite的博客 957

LeetCode #394 - Decode String -Medium

ProblemGiven an encoded string, return it's 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

Arcome的博客 449

Python+Flask+Echarts打造全国气象数据可视化分析大屏

本文详细介绍了如何使用Python+Flask+Echarts构建全国气象数据可视化分析大屏,实现实时监控、趋势分析和快速决策。通过Python强大的数据处理能力、Flask的轻量级优势和Echarts的交互体验,打造高效的气象数据可视化系统,提升农业、物流等行业的决策效率。

weixin_29061531的博客 1071

LeetCode 394. Decode String 题解

本题是栈的经典应用问题,主要考察对栈数据结构的理解和使用。通过使用栈,我们可以高效地解码字符串。栈的核心思想是:使用两个栈,一个用于存储数字,一个用于存储字符串,当遇到左括号时,将当前数字和字符串压入栈中,当遇到右括号时,弹出数字和字符串,将当前字符串重复数字次,然后与弹出的字符串拼接。这种方法不仅适用于字符串解码问题,还可以应用于许多其他需要处理嵌套结构的问题。掌握栈的使用,对于解决这类问题非常重要。

cannonjinx的博客 4056

X光安检模型训练第一步:手把手教你处理OPIXray和HIXray这两个小众数据集

本文详细解析了X光安检AI模型训练的关键步骤,重点介绍如何处理OPIXray和HIXray这两个专业数据集。从数据格式转换到YOLO标准,再到数据增强和质量验证,手把手指导开发者高效利用这些数据集进行目标检测模型训练,提升安检场景下的危险物品识别准确率。

weixin_32629853的博客 321

ArcMap学习笔记(三)地图数字化

地图数字化前言地图数字化实现步骤1.加载地形图2.新建要素图层3.开启编辑环境4.设置捕捉环境5.选择数字化图层6.数字化控制点7.数字化等高线8.数字化图幅边框9.保存数字化成果总结 前言 使用软件:ArcMap10.4.1中文版 如果出现侵权,请在评论留言,我会及时删除,谢谢。 地图数字化 空间数据采集(输入)是将现有的地图、外业观测成果、航空像片、遥感图片数据、文本资料等转换成GIS可以直接...

JayWang博客 1万+

Decode String (LeetCode)

Given an encoded string, return its decoded string. The encoding rule is:k[encoded_string], where theencoded_stringinside the square brackets is being repeated exactlyktimes. Note thatkis guar...

“点点”专栏 351

晶体管的 栅极gate 材料选用 多晶硅polysilicon,并采用 自对准工艺 self-aligned IC后端版图 【VLSI】

本文为了解决为什么要使用多晶硅作栅极触点的问题,先介绍了MOS管的工作原理是通过栅极上所加的电压控制漏极与源极之间电流,然后解释了栅极的材料为什么选用多晶硅,然后介绍了晶体管里栅极的自对准工艺(Self-Aligned Gate )。

Jie_MSD的博客 1万+

LeetCode394:Decode String

Given an encoded string, return it's decoded string. The encoding rule is:k[encoded_string], where theencoded_stringinside the square brackets is being repeated exactlyktimes. Note thatkis gua...

卷卷萌的博客 280

从外包到转正:一个华为OD亲历者的真实工作体验与避坑指南

本文分享了一位华为OD员工从外包到转正的真实经历与实用建议。通过详细解析华为OD的日常工作、转正核心指标、机试备考技巧及职场突围策略,为读者提供了一份全面的避坑指南。特别针对机试E卷的高频考点和刷题方法,给出了具体的数据分析和实战经验。

weixin_33686714的博客 740

通过电源模块降低电源噪声的3种方法

电源噪声是一种常见且不受欢迎的电气现象。如果不降低噪声,其会对敏感的医疗、测试测量、航空航天和国防系统的应用性能产生不利影响。当今的高精度模拟信号链系统需要直流/直流开关稳压器产生稳压电源轨,为低噪声应用中的模数转换器(ADC)、数模转换器(DAC)、现场可编程门阵列(FPGA)及其子系统供电。尽管直流/直流开关稳压器具有高工作效率,它们的开关操作会导致较大的不连续电流,从而产生较高的输入和输出电压纹波、频率尖峰和宽带噪声。

qq_43416206的博客 1439

[leetcode] 394. Decode String

Description Given an encoded string, return it’s decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note th...

Learning from the mistakes 263

微信小程序 - 最新获取用户昵称 / 头像(wx.getUserProfile 接口被废弃后的代替方案)详细教程,2022 年之后的所有微信小程序,获取用户信息最新详细教程,附带示例源代码

微信小程序wx.getUserProfile接口废了用什么代替,微信小程序wx.getUserProfile不能用了怎么办,wx.getUserProfile失效有什么替代方案吗,微信新规定头像昵称填写最新教程,目前微信小程序最新获取用户头像昵称教程,微信小程序用户头像昵称获取规则调整公告,2022改版后的微信小程序如何获取用户头像和昵称信息,微信小程序官方废弃getUserProfile后如何实现获取用户信息,微信小程序wx.getUserProfile接口返回了默认头像昵称,微信小程序获取用户信息不

🏆 前端领域优质创作者 2万+

【leetcode】394. Decode String【M】【45ms】

Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note thatk is

sscssz的博客 716

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

LeetCode(394):字符串解码 Decode String(Java)

2019.10.19 #程序员笔试必备# LeetCode 从零单刷个人笔记整理(持续更新) github:https://github.com/ChopinXBP/LeetCode-Babel 比较简单的一道逻辑题,但是要注意不能出错。 借助辅助栈遍历字符串,遇到数字时,栈中依次存入:数字的起始位置,数字大小,字符串的起始位置;遇到’]’,对原字符串进行替换并重置计数器位置。 传送门:字符串...

NJU_ChopinXBP的博客 453

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

LeetCode-394:Decode String(字符串解码)

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

凌凌岛的博客 337

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

394. Decode String

https://leetcode.com/problems/decode-string/description/ 题目描述 Given an encoded string, return it's decoded string. The encoding rule is:k[encoded_string], where theencoded_stringinside the sq...

weixin_41838371的博客 235

leetcode(394). Decode String

problem Given an encoded string, return it’s decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. No

qishi的博客 535

[LeetCode Python3] 394. Decode String + 递归

394. Decode String class Solution: def decodeString(self, s: str) -> str: table = "0123456789" size = len(s) index = 0 res = "" while index < size: if s[index] in table: # 若遇到数字即进入解码

xvrixingkong的博客 259

LeetCode 394 Decode String 用编译原理的角度来解这道题

题目如下: Given an encoded string, return its decoded string. The encoding rule is:k[encoded_string], where theencoded_stringinside the square brackets is being repeated exactlyktimes. Note thatk...

u012121468的博客 315

leetcode-394-Decode String

原题: Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated ex...

weixin_34221775的博客 104

[LeetCode] 394. Decode String

题:https://leetcode.com/problems/queue-reconstruction-by-height/description/ 题目 Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), ...

u013383813的博客 132

[LeetCode题解] 394. 字符串解码

题目链接: https://leetcode-cn.com/problems/decode-string/. 这道题是我在公司模拟自测的时候遇到的一道题。 参照题解区大佬的思路: 由于括号内嵌套括号,与栈的先进后出一致。 class Solution(object): def decodeString(self, s): """ :type s: str ...

m0_46134602的博客 197

Python | Leetcode Python题解之第394题字符串解码

Python | Leetcode Python题解之第394题字符串解码

Mopes__的博客 620

【LeetCode】394. 字符串解码

栈的基本使用。但是需要注意的是,在入栈的过程中,可能数字并非只是单个字符,所以需要把一整串数字全部入到栈中。

说文科技,做有态度的研究。 280

DFS+回溯专题12 - leetcode95. Unique Binary Search Trees II/394. Decode String - Mark

95. Unique Binary Search Trees II 题目描述 给定整数n,产生存储1…n的结构上唯一的二叉搜索树。 例子 Input: 3 Output: [ [1,null,3,2], [3,2,null,1], [3,1,null,null,2], [2,1,3], [1,null,2,null,3] ] 思想 解法 ...

libh的博客 183
上一篇: LeetCode #347 - Top K Frequent Elements
下一篇: LeetCode #406 - Queue Reconstruction by Height
LawFile
博客等级 码龄10年 5粉丝 627原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址