davegimo

Untitled

Dec 16th, 2022
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. def somma_liv_pari(A):
  2.     return aux(A,0)
  3.  
  4.  
  5. def aux(A,livello):
  6.     if A is None:
  7.         return 0
  8.  
  9.     if A.sx is None and A.dx is None:
  10.         if livello % 2 == 0:
  11.             return A.val
  12.         return 0
  13.  
  14.     somma = 0
  15.     if livello % 2 == 0:
  16.             somma = A.val
  17.  
  18.     if A.sx is not None:
  19.         somma += aux(a.sx,livello + 1)
  20.  
  21.     if A.dx is not None:
  22.         somma += aux(a.dx,livello + 1)
  23.  
  24.     return somma
Advertisement
Add Comment
Please, Sign In to add comment