题目描述
用数组模拟链表,对于每一个字符存一个next值表示下一个元素的下标
对于字符[,将当前下标改为0
对于字符],将当前下标改为last就是我们存的最后的下标
对于其他字符,更新next即可
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int last,now,nxt[100005];
int main(){
while(~scanf("%s",s+1)){
int n=strlen(s+1);
last=0;
now=0;
nxt[0]=0;
for(int i=1;i<=n;i++){
char ch=s[i];
if(ch=='[')now=0;
else if(ch==']')now=last;