Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package construct_string_from_binary_tree

import . "github.com/openset/leetcode/internal/kit"
import (
"strconv"

. "github.com/openset/leetcode/internal/kit"
)

/**
* Definition for a binary tree node.
Expand All @@ -11,5 +15,17 @@ import . "github.com/openset/leetcode/internal/kit"
* }
*/
func tree2str(t *TreeNode) string {
return ""
ans := ""
if t != nil {
ans += strconv.Itoa(t.Val)
if t.Left != nil {
ans += "(" + tree2str(t.Left) + ")"
} else if t.Right != nil {
ans += "()"
}
if t.Right != nil {
ans += "(" + tree2str(t.Right) + ")"
}
}
return ans
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func TestTree2str(t *testing.T) {
tests := [...]caseType{
{
input: []int{1, 2, 3, 4},
expected: "",
expected: "1(2(4))(3)",
},
{
input: []int{1, 2, 3, NULL, 4},
expected: "",
expected: "1(2()(4))(3)",
},
}
for _, tc := range tests {
Expand Down