@@ -39,9 +39,14 @@ func DeserializeListNode(s string) (*ListNode, error) {
39
39
return root , nil
40
40
}
41
41
42
- // ToString returns a string representation of the linked list.
43
- // It panics with ErrInfiniteLoop if a cycle is detected.
42
+ // ToString is deprecated, use String()
44
43
func (l * ListNode ) ToString () string {
44
+ return l .String ()
45
+ }
46
+
47
+ // String returns a string representation of the linked list.
48
+ // It panics with ErrInfiniteLoop if a cycle is detected.
49
+ func (l * ListNode ) String () string {
45
50
seen := make (map [* ListNode ]bool , 10 )
46
51
47
52
sb := & strings.Builder {}
@@ -116,9 +121,14 @@ func DeserializeTreeNode(s string) (*TreeNode, error) {
116
121
return root , nil
117
122
}
118
123
119
- // ToString returns a string representation of the binary tree.
120
- // It panics with ErrInfiniteLoop if a cycle is detected.
124
+ // ToString is deprecated, use String()
121
125
func (t * TreeNode ) ToString () string {
126
+ return t .String ()
127
+ }
128
+
129
+ // String returns a string representation of the binary tree.
130
+ // It panics with ErrInfiniteLoop if a cycle is detected.
131
+ func (t * TreeNode ) String () string {
122
132
nodes := []* TreeNode {}
123
133
queue := []* TreeNode {t }
124
134
seen := make (map [* TreeNode ]bool , 10 )
@@ -184,9 +194,14 @@ func DeserializeNaryTreeNode(s string) (*NaryTreeNode, error) {
184
194
return root .Children [0 ], nil
185
195
}
186
196
187
- // ToString returns a string representation of the nary tree.
188
- // It panics with ErrInfiniteLoop if a cycle is detected.
197
+ // ToString is deprecated, use String
189
198
func (t * NaryTreeNode ) ToString () string {
199
+ return t .String ()
200
+ }
201
+
202
+ // String returns a string representation of the nary tree.
203
+ // It panics with ErrInfiniteLoop if a cycle is detected.
204
+ func (t * NaryTreeNode ) String () string {
190
205
nodes := []* NaryTreeNode {}
191
206
q := []* NaryTreeNode {{Children : []* NaryTreeNode {t }}}
192
207
seen := make (map [* NaryTreeNode ]bool , 10 )
0 commit comments