public class Solution {
public boolean isValidSerialization(String preorder) {
String[] s = preorder.split(",");
int nulls = 1;
for (String str : s) {
if (--nulls < 0) return false;
if (!str.equals("#")) nulls += 2;
}
return nulls == 0;
}
}
LeetCode 331. Verify Preorder Serialization of a Binary Tree
最新推荐文章于 2025-08-21 20:43:22 发布