LeetCode 331. Verify Preorder Serialization of a Binary Tree

来源:互联网 发布:多方通话软件 编辑:程序博客网 时间:2024/05/16 04:40
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;    }}

0 0
原创粉丝点击