1 開始想用dfs做煞檩,其實(shí)這道題也可以用BFS做粘招,一個(gè)一個(gè)level掃描啥寇,遇到無子節(jié)點(diǎn)的,就append這條path洒扎,path的形式是string辑甜;同時(shí)queue中存root到當(dāng)前節(jié)點(diǎn)的path
Time complexity: O(n)
Space complexity: O(h) h is the height of tree
1 開始想用dfs做煞檩,其實(shí)這道題也可以用BFS做粘招,一個(gè)一個(gè)level掃描啥寇,遇到無子節(jié)點(diǎn)的,就append這條path洒扎,path的形式是string辑甜;同時(shí)queue中存root到當(dāng)前節(jié)點(diǎn)的path
Time complexity: O(n)
Space complexity: O(h) h is the height of tree