nikunjsoni

331

Apr 3rd, 2021
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution:
  2.     def isValidSerialization(self, preorder: str) -> bool:
  3.         seq = preorder.split(',')
  4.         # For binary tree.. #nodes = #edges + 1
  5.         edges = 1
  6.         for p in seq:
  7.             edges = edges-1
  8.             if edges < 0:
  9.                 return False
  10.             if p != '#':
  11.                 edges = edges+2
  12.        
  13.         return edges == 0
RAW Paste Data