class INT:
def __init__(self):
self.a = 0
class Node:
def __init__(self, data):
self.left = None
self.right = None
self.data = data
def newNode(data):
node = Node(data)
return node
def height(root):
if (root == None):
return 0;
lheight = height(root.left)
rheight = height(root.right)
return max(lheight, rheight) + 1
def LevelOrder(root, level, count):
if (root == None):
return;
if (level == 1 and
root.left != None and
root.right != None):
count.a += 1
elif (level > 1):
LevelOrder(root.left,
level - 1, count)
LevelOrder(root.right,
level - 1, count)
def CountFullNodes(root, kids):
h = height(root)
count = INT()
LevelOrder(root, kids, count)
return count.a
if __name__ == "__main__":
root = newNode(7)
root.left = newNode(5)
root.right = newNode(6)
root.left.left = newNode(8)
root.left.right = newNode(1)
root.left.left.left = newNode(2)
root.left.left.right = newNode(11)
root.right.left = newNode(3)
root.right.right = newNode(9)
root.right.right.right = newNode(13)
root.right.right.left = newNode(10)
root.right.right.right.left = newNode(4)
root.right.right.right.right = newNode(12)
kids = 2
print(CountFullNodes(root, kids))
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}