0

I'm running a BST in Python, with the following code:

def findOdd(head):
    ary = []
    ary = BST_size(head, ary)
    print ary
    return ary

def BST_size(root, ary2):
    if root is None:
        print ary2
        return ary2
    if root.data % 2 != 0:
        print "yes"
        ary2.append(root.data)
        BST_size(root.left, ary2)
        BST_size(root.right, ary2)
    else:
        BST_size(root.left, ary2)
        BST_size(root.right, ary2)

As you can see, the goal is to return an array of the odd values within the array, however, when I run it, ary2 equals an array of the odd values, but ary simply equals None. EDIT: I changed to code to this and I'm still getting an error:

def findOdd(head):
    ary = []
    print BST_size(head, ary)
    return BST_size(head, ary)


def BST_size(root, ary2):
    if root is None:
        return ary2
    if root.data % 2 != 0 and root.data not in ary2:
        ary2.append(root.data)
        BST_size(root.left, ary2)
        BST_size(root.right, ary2)
    else:
        BST_size(root.left, ary2)
        BST_size(root.right, ary2)
pulsar100
  • 41
  • 7

0 Answers0