You are viewing a single comment's thread. Return to all comments →
import xml.etree.ElementTree as etree maxdepth = 0 def depth(elem, level): global maxdepth level += 1 maxdepth = max(maxdepth,level) for child in elem: depth(child,level) if __name__ == '__main__': n = int(input()) xml = "" for i in range(n): xml = xml + input() + "\n" tree = etree.ElementTree(etree.fromstring(xml)) depth(tree.getroot(), -1) print(maxdepth)
Seems like cookies are disabled on this browser, please enable them to open this website
XML2 - Find the Maximum Depth
You are viewing a single comment's thread. Return to all comments →