Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #contare elementi == k
- def conta(A,k):
- if A is None:
- return 0
- contavalore = 0
- if A.val == k:
- contavalore += 1
- return contavalore + conta(a.sx,k) + conta(a.dx,k)
- def verifica_almeno_2(A,k):
- return conta(A,k) >= 2
- #########
- def es1(A,B):
- if A is None:
- return 0
- if A.sx is None and A.dx is None:
- return verifica_almeno_2(B,a.val)
- return somma_cammini_foglie(A.sx,B,A.val) or somma_cammini_foglie(A.dx,B,A.val)
- def somma_cammini_foglie(A,B, somma_corrente):
- if A is None:
- return False
- if A.sx is None and A.dx is None:
- return verifica_almeno_2(B,somma_corrente + a.val)
- return somma_cammini_foglie(A.sx,B, somma_corrente + a.val) or somma_cammini_foglie(A.dx,B, somma_corrente + a.val)
Advertisement
Add Comment
Please, Sign In to add comment