首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
字符串解码
[编程题]字符串解码
热度指数:3384
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
给一个加密过的字符串解码,返回解码后的字符串。
加密方法是:k[c] ,表示中括号中的 c 字符串重复 k 次,例如 3[a] 解码结果是 aaa ,保证输入字符串符合规则。不会出现类似 3a , 3[3] 这样的输入。
数据范围:输出的字符串长度满足
示例1
输入
"3[a]"
输出
"aaa"
示例2
输入
"abc"
输出
"abc"
示例3
输入
"3[3[b]]"
输出
"bbbbbbbbb"
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(0)
邀请回答
收藏(63)
分享
纠错
提交结果有问题?
11个回答
18篇题解
开通博客
godhands
发表于 2022-01-13 17:28:02
描述 题目描述 首先给定我们一个字符串,在这个字符串里面,方括号前面的数字是我们要重复的倍数,方括号里面的字符串是我们要重复,然后让我们输出最后的结果 样例解释 首先我们的样例输入是 "3[3[b]]" 这个我们先从里面的方括号入手,我们先把里面的bbb扩大三倍,也就是说我们可以得到bbbbbbb
展开全文
fred-coder
发表于 2022-01-27 10:51:37
利用两个栈记录嵌套的字符串和数字; 在遇到 "[" 时,将数字和当前字符串入栈 在遇到 "]" 时,将数字出栈与当前字符串相乘再加上字符串栈中的结果得到该层嵌套中的字符串,然后赋值给当前值 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param
展开全文
姐姐的遮阳伞
发表于 2022-03-31 01:23:22
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @re
展开全文
代码界的小白
发表于 2022-01-05 16:39:11
题目主要信息 给一个加密过的字符串解码,返回解码后的字符串。 加密方法是:k[c] ,表示中括号中的 c 字符串重复 k 次,例如 3[a] 解码结果是 aaa ,保证输入字符串符合规则。不会出现类似 3a , 3[3] 这样的输入。 方法一:使用栈 具体方法 本题中可能出现括号嵌套的情况,比如
展开全文
太阳hxy
发表于 2023-08-29 13:05:31
class Solution { public: string decodeString(string s) { //定义两个栈 //栈1用于括号的匹配 //栈2用于辅助反转字符串 stack<char>stack1
展开全文
17c89
发表于 2024-05-09 17:38:01
import java.util.*; /** * NC199 字符串解码 * @author d3y1 */ public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * *
展开全文
江川健一
发表于 2022-10-16 17:03:31
高端的食材往往只需要最朴素的烹饪方式,忙碌了两个小时,陈师傅泡了一桶康师傅。
CroMarmot
发表于 2022-01-03 20:34:53
题意 把压缩过的字符串还原, 压缩过的通过次数[字符串]来表示 范围: 输出长度不会超过50 方法 每次枚举展开 按照题意,我们可以从内到外进行解码. 那第一个出现的右侧括号所包含的内容,就是最内层的. 这样每次解码一块内容更新整个字符串.直到字符串被完全解码为止,就是要求的答案 代码 class
展开全文
苦行潜修者
发表于 2024-04-23 09:20:20
using System; using System.Collections.Generic; using System.Text; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * *
展开全文
牛客327297870号
发表于 2023-03-04 21:18:32
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @return(756076230) string字符串 # class Solution: def decodeString(self , s: st
展开全文
问题信息
字符串
栈
递归
难度:
11条回答
63收藏
3453浏览
热门推荐
通过挑战的用户
查看代码
La+拉普拉斯
2022-11-25 13:59:01
枉做好人
2022-09-17 17:01:29
外骨骼
2022-09-17 00:12:45
Asphyxiay
2022-09-14 01:55:36
亮里格亮
2022-09-13 15:42:34
相关试题
执行完下列语句段后,i值为()
递归
评论
(15)
设某二叉树的先序遍历序列为abdg...
树
评论
(1)
之前的经历中单品数据分析的经验丰富...
评论
(1)
什么样的人适合做数据分析
评论
(1)
2022 诺瓦科技 Perl re...
perl
System Verilog
评论
(1)
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ public String decodeString (String s) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ string decodeString(string s) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @return string字符串 # class Solution: def decodeString(self , s ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ public string decodeString (string s) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ function decodeString( s ) { // write code here } module.exports = { decodeString : decodeString };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @return string字符串 # class Solution: def decodeString(self , s: str) -> str: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ func decodeString( s string ) string { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ char* decodeString(char* s ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @return string字符串 # class Solution def decodeString(s) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ def decodeString(s: String): String = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ fun decodeString(s: String): String { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ public String decodeString (String s) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ export function decodeString(s: string): string { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ func decodeString ( _ s: String) -> String { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ pub fn decodeString(&self, s: String) -> String { // write code here } }
"3[a]"
"aaa"
"abc"
"abc"
"3[3[b]]"
"bbbbbbbbb"