Problematic test case


  • 0
    P

    It tells me wrong answer on this case:

    [41,37,44,24,39,42,48,1,35,38,40,null,43,46,49,0,2,30,36,null,null,null,null,null,null,45,47,null,null,null,null,null,4,29,32,null,null,null,null,null,null,3,9,26,null,31,34,null,null,7,11,25,27,null,null,33,null,6,8,10,16,null,null,null,28,null,null,5,null,null,null,null,null,15,19,null,null,null,null,12,null,18,20,null,13,17,null,null,22,null,14,null,null,21,23]
    

    Then I tried to use a piece of python code to print the value path to value '5' in the tree, kind of ugly , but work

    null="null"
    l=[null,41,37,44,24,39,42,48,1,35,38,40,null,43,46,49,0,2,30,36,null,null,null,null,null,null,45,47,null,null,null,null,null,4,29,32,null,null,null,null,null,null,3,9,26,null,31,34,null,null,7,11,25,27,null,null,33,null,6,8,10,16,null,null,null,28,null,null,5,null,null,null,null,null,15,19,null,null,null,null,12,null,18,20,null,13,17,null,null,22,null,14,null,null,21,23]
    for i in range(len(l)):
        if l[i]==5:
            break;
    p=[]
    while i>0:
        p.append(i);
        i=i/2;
    i=len(p)-1
    while i>=0:
        print l[p[i]]
        i=i-1
    

    Output is:

    41
    37
    24
    1
    2
    29
    5
    

    Did you notice the 29? 29 should be on the right of 24, so when 1 follow 24, that means the path goes left from 24, all value following should less than 24, but 29 breaks the BST rule, and cause my code fault. Can you check it? If I made some mistakes here, please also point out, thank you.


  • 0
    L

    The path to 29 is 41-37-24-35-30-29 in your case. Check it :)


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.