單步調試調試leetcode代碼
LeetCode代碼通過Playground獲取調試代碼,然后通過賦值代碼到本地的Pycharm進行單步調試
概述
LeetCode有三種Playground:控制台Playground:鏈表(Linked list),樹(Binary tree);前端程序:React。LeetCode里面的Playground調試只能通過stdin輸入實例,執行調試之后直接就獲得輸入結果。通過復制粘貼Playground代碼到Pycharm可以進行單步調試。不同的控制台Playground調試過程類似,本文以104. 二叉樹的最大深度中的樹(Binary tree)的控制台Playground和Pycharm進行單步執行從而調試自己寫的代碼。
一、選擇語言,輸入調試代碼
二、通過Playground獲取調試代碼
1、代碼提交平台跳轉到Playground
2、復制粘貼Playground當中全部的代碼
三、通過Pycharm調試代碼
1、修改代碼:ctr +R 將null全改成None
2、設置斷點,單擊連接調試。在控制台輸入測試實例(enter),進行單步調試。stdin實例中需要將null全改成None
3、進行單步調試獲取代碼bug的位置並進行修改獲得運行結果如下,具體運行過程在調試器中可以查看
4、'str' object has no attribute 'decode'
python3的不需要decode了,因為python3的str沒有decode的這個屬性了,直接刪除!
def stringToString(input):
return input[1:-1].decode('string_escape')
修改為:
def stringToString(input):
return input[1:-1]