题解 | #二叉树#
二叉树
https://www.nowcoder.com/practice/f74c7506538b44399f2849eba2f050b5
#include <stdio.h> #include <stdlib.h> #include <string.h> int num(int m, int n) { if (m > n||n==0) { return 0; } else { int left = num(2 * m, n); int right = num(2 * m + 1, n); return 1 + left + right; } } int main() { int n;// 二叉树的最后一个节点 int m;// 以m为根节点的子树 while(scanf("%d %d", &m,&n)!=EOF) { int count = num(m, n); // 计算有多少个结点 printf("%d\n",count); } return 0; }