/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/funcfindMode(root*TreeNode)[]int{// -10^5 <= root.Val <= 10^5
// base initially is zero
varbase,count,maxCountintvarans[]intupdate:=func(valint){ifval==base{count++}else{base,count=val,1}ifcount==maxCount{ans=append(ans,base)}elseifcount>maxCount{ans=[]int{base}maxCount=count}}varinorderfunc(root*TreeNode)inorder=func(root*TreeNode){ifroot==nil{return}inorder(root.Left)update(root.Val)inorder(root.Right)}inorder(root)returnans}