原題:
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the result should return the new root of the trimmed binary search tree

Screen Shot 2017-11-05 at 4.49.41 PM.png

Screen Shot 2017-11-05 at 4.51.37 PM.png
所犯的錯(cuò)誤:
開(kāi)始21,28行沒(méi)有做賦值給root,導(dǎo)致出錯(cuò)。root是作為對(duì)象傳入給函數(shù)的,如果不將返回值賦值給root,那么原來(lái)的Root等于沒(méi)有任何函數(shù)操作所帶來(lái)的改變。

Screen Shot 2017-11-05 at 4.53.16 PM.png
開(kāi)始第18,22都沒(méi)有寫(xiě)elif ,只是寫(xiě)了if。由于root可能在上一個(gè)if語(yǔ)句中發(fā)生變化,導(dǎo)致符合下一個(gè)If的條件,又進(jìn)入了下一個(gè)if,這樣就發(fā)生了錯(cuò)誤。必須采用elif將他們互斥。
開(kāi)始沒(méi)有寫(xiě)28,21行,而在函數(shù)最后的return中這樣寫(xiě):return self.trimBST(root,L,R),導(dǎo)致程序進(jìn)入無(wú)限循環(huán)而溢出棧。