这里是10.23随笔。
今天我又发现了一种不一样的解题方法,题是昨天的题,这个方法是迭代,代码留档:
int degreeOneNodesIterative(struct TreeNode* root) {
if (root == NULL) {
return 0;
}
int count = 0;
struct TreeNode* current;
SqQueue queue;
InitQueue(&queue);
EnQueue(&queue, root);
while (!IsEmpty(&queue)) {
DeQueue(&queue, ¤t);
if (current->left != NULL && current->right == NULL) {
count++;
}
if (current->left == NULL && current->right != NULL) {
count++;
}
if (current->left != NULL) {
EnQueue(&queue, current->left);
}
if (current->right != NULL) {
EnQueue(&queue, current->right);
}
}
return count;
}
标签:count,queue,10.23,随笔,current,right,NULL,left From: https://www.cnblogs.com/Thanatos-syst/p/18498515