小编Peg*_*asy的帖子

寻找一棵树的深度?

我对二叉树和递归非常陌生。我的程序是查找树的高度,但是对于为什么我的程序不起作用,我有点困惑。

struct Node {
    int value;
    Node *left;
    Node *right;
}

int heightOfTree(Node node){
    if(node ==NULL)
    {
         return 0;
    }
    else
    {
       int lheight=heightOfTree(node->left);
       int rheight = heightOfTree(node->right);
       if(lheight>rheight)
       {
           return lheight;
       }
       else
       {
           return rheight;
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

我在网上跟踪了伪代码,所以我自己实现了它,因为我不想只复制粘贴。我试图插入很多节点,但是当我运行程序时,我总是得到0高度吗?谢谢

algorithm recursion data-structures

3
推荐指数
1
解决办法
884
查看次数

正则表达式匹配大于1的任何整数

我最近才开始使用正则表达式,并且试图找出如何匹配大于1的任何数字的模式。到目前为止,我想到了

[2-9][0-9]*
Run Code Online (Sandbox Code Playgroud)

但是它仅适用于最左边的数字不为1的情况。例如,234有效但124无效。

因此,我想要实现的是1不应该匹配一个数字,任何大于它的整数。

regex

3
推荐指数
2
解决办法
8877
查看次数

标签 统计

algorithm ×1

data-structures ×1

recursion ×1

regex ×1