classSolution{public:NestedIntegerdeserialize(strings){if(s[0]!='[')returnNestedInteger(stoi(s));stack<NestedInteger>stack;intstart;// The start index of numfor(inti=0;i<s.length();++i){switch(s[i]){case'[':stack.push(NestedInteger());start=i+1;break;case',':if(i>start){constintnum=stoi(s.substr(start,i));stack.top().add(NestedInteger(num));}start=i+1;break;case']':NestedIntegerpopped=stack.top();stack.pop();if(i>start){constintnum=stoi(s.substr(start,i));popped.add(NestedInteger(num));}if(stack.empty())returnpopped;elsestack.top().add(popped);start=i+1;break;}}throw;}};