public class Solution { List<int> list = new List<int>(); private void postTree(TreeNode root) { if (root != null) { list.Add(root.val); if (root.left != null) { postTree(root.left); } if (root.right != null) { postTree(root.right); } } } public bool IsUnivalTree(TreeNode root) { postTree(root); var count = list.GroupBy(x => x).Count(); if (count == 1) { return true; } return false; } }