题解 | #二叉树#
二叉树
https://www.nowcoder.com/practice/f74c7506538b44399f2849eba2f050b5
用BFS思想实现,不用递归
#include <iostream>
#include <queue>
using namespace std;
int main() {
int n, m;
while (scanf("%d %d", &m, &n) != EOF) {
if(m==0 && n==0){
break;
}
int total = 0;
queue<int> myQueue;
myQueue.push(m);
while (!myQueue.empty()) {
int current = myQueue.front();
myQueue.pop();
if(current>n){
continue;
}
total++;
myQueue.push(current*2);
myQueue.push(current*2+1);
}
cout<<total<<endl;
}
return 0;
}
迅雷公司福利 193人发布
查看16道真题和解析