1class Solution {2 public:3 bool isValidSerialization(string preorder) {4 stringstream s(preorder);5 string str;6 int slots = 1;7 while (getline(s, str, ',')) {8 if (slots == 0) return 0;9 if (str == "#")10 slots--;11 else12 slots++;13 }14 return slots == 0;15 }16};
WPM •0 •0
ACC •0 •0
TIME •0