I am trying to solve equivalent binary trees exercise on go tour. Here is what I did;
package main
import \"tour/tree\"
import \"fmt\"
// Walk walks the tr
You got it almost right, there's no need to use the select
statement because you will go through the default
case too often, here's my solution that works without needing to count the number of nodes in the tress:
func Same(t1, t2 *tree.Tree) bool {
ch1, ch2 := make(chan int), make(chan int)
go Walk(t1, ch1)
go Walk(t2, ch2)
for i := range ch1 {
j, more := <-ch2
if more {
if i != j { return false }
} else { return false }
}
return true
}