You are viewing a single comment's thread. Return to all comments →
I agree, the purely functional approach is probably better in hindsight for any real life application. The solution passing the var down would have avoided possible external side effects where mine uses a global variable.
I used the same approach, using the inorder traversal. But in my case I've used an instance of a class for storing the last value. Is it a good practise to do this?
last = None
variable = staticVar()
if root != None:
if not checkBST(root.left):
if variable.last != None and variable.last.data >= root.data:
variable.last = root