Wierd thing happens.....


  • 0
    Q

    I think my code is wrong and i was just testing, never expected it goes through... But the system accept this solution.... Any idea why this is right?... Thanks!

    class Solution:
            # @param root, a tree node
            # @return a list of integers
            def inorderTraversal(self, root):
                if root == None:
                    return []
                    
                current=root
                current1=root
                
                while current.left != None or current.right != None:
                    
                    if current.left != None and current.right != None:
                        current1=current
                        current=current.left
                        return self.inorderTraversal(current1.left)+[current1.val]+self.inorderTraversal(current1.right)
                        
                    if current.left != None and current.right == None:
                        current1=current
                        current=current.left
                        return self.inorderTraversal(current1.left)+[current1.val]
                        
                    if current.left == None and current.right != None:
                        current1=current
                        current=current.right
                        return [current1.val]+self.inorderTraversal(current1.right)
                return [root.val]

Log in to reply
 

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