public List <string> GetAllPaths(LCTreeNode root)
        {
            _results = new List <string>();

            GetPaths(root, "");
            return(_results);
        }
Пример #2
0
        //LC104
        public int GetMaxDepth(LCTreeNode node)
        {
            if (node == null)
            {
                return(0);
            }

            return(Math.Max(GetMaxDepth(node.Left),
                            GetMaxDepth(node.Right)) + 1);
        }
Пример #3
0
        //todo: 实现有问题 LC111
        public int GetMinDepth(LCTreeNode node)
        {
            if (node == null)
            {
                return(0);
            }
            if (node.Left == null && node.Right == null)
            {
                return(1);
            }

            return(Math.Min(GetMinDepth(node.Left),
                            GetMinDepth(node.Right)) + 1);
        }
        private void GetPaths(LCTreeNode node, string path)
        {
            if (node == null)
            {
                return;
            }

            if (node.Left == null && node.Right == null)
            {
                var onePath = string.Concat(path, "->" + node.Value.ToString());
                _results.Add(onePath);
            }

            GetPaths(node.Left, path + ((string.IsNullOrEmpty(path))? "":"->") + node.Value.ToString());
            GetPaths(node.Right, path + ((string.IsNullOrEmpty(path))? "":"->") + node.Value.ToString());
        }