- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有树节点,我想找到树节点中最深的子节点。如果有 2 个子节点分别具有 level 11
和 level 13
那么我需要 unction 返回值 13。
我该怎么做?
public int FindLevel(TreeNode oParentNode)
{
counter++;
forech(TreeNode oSubNode in oParentNode.Nodes)
{
FindLevel(oParentNode);
}
return Counter;
}
最佳答案
这是我给你的建议:
private int GetDeepestChildNodeLevel(TreeNode node)
{
var subLevel = node.Nodes.Cast<TreeNode>().Select(GetDeepestChildNodeLevel);
return subLevel.Count() == 0 ? 1 : subLevel.Max() + 1;
}
这里有显式类型:
private int GetDeepestChildNodeLevel(TreeNode node)
{
var subLevel = node.Nodes.Cast<TreeNode>().Select<TreeNode, int>(subNode => GetDeepestChildNodeLevel(subNode));
return subLevel.Count<int>() == 0 ? 1 : subLevel.Max() + 1;
}
关于c# - 查找 Deepest child Treenode 的层级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8310601/
我需要一些帮助来查询分层数据。这是一个简单的表,其中 parent_id 引用 id 并且对于根条目可能为 null。 create table edition ( id
对于类似于 this one 的研究项目我想从 python documentation. 中提取所有“文档单元”python 文档中的文档单元可以是(作为 html-meta 标记): 方法(dl
我有一个关于设计以 JSON 格式返回和接受数据的 RESTful API 的“概念性”问题。 考虑以下请求和响应: GET http://host/records/12345 { "id":"123
我有一个 map> . 第一个键代表节点,第二个键代表一个属性,'最深'元素代表一个特定的值。 我需要检查该元素,但执行以下不必要的操作会向我的 map 添加键: map> test; if (tes
我有树节点,我想找到树节点中最深的子节点。如果有 2 个子节点分别具有 level 11 和 level 13 那么我需要 unction 返回值 13。 我该怎么做? public int Find
这个问题已经有答案了: nested li - on clicking child, parent click event triggered [duplicate] (1 个回答) 已关闭 9 年前
我知道 e.target 包含光标正下方元素的信息,但是如果我想知道其中有一个 table>tr>td>button 的 div 的类名怎么办,我是单击该 td 内的那个按钮。我知道这个事件会冒泡,应
题目 https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/ 题解 /** * Definition f
总结 我正在使用 Ruby(在我的机器上为 ruby 2.1.2p95 (2014-05-08) [x86_64-linux-gnu],在生产环境中为 ruby 1.9.3p484 (2013-11-
我是一名优秀的程序员,十分优秀!