题目:

题解:
#define MAX_NODE_NUM 100
int* rightSideView(struct TreeNode* root, int* returnSize){
    if (root == NULL) {
        *returnSize = 0;
        return NULL;
    }
    int *res = (int *)malloc(sizeof(int) * MAX_NODE_NUM);
    int cnt = 0;
    struct TreeNode **record = (struct TreeNode **)malloc(sizeof(struct TreeNode *) * MAX_NODE_NUM);
    int head = 1;
    int tail = 0;
    record[0] = root;
    
    while (head > tail) {
        int turn = head - tail;
        for (int i = 0; i < turn; i++) {
            struct TreeNode *cur = record[tail + i];
            if (cur->left != NULL) {
                record[head++] = cur->left;
            }
            if (cur->right != NULL) {
                record[head++] = cur->right;
            }
            if (i == turn - 1) {
                res[cnt++] = cur->val;
            }
        }
        tail += turn;
    }
    *returnSize = cnt;
    return res;
}
                





![[图解]分析模式高阶+课程讲解03物品模式](https://img-blog.csdnimg.cn/direct/b0960148e0c8448c91ca5265137ae2df.png)


![[Cloud Networking] OSPF](https://img-blog.csdnimg.cn/direct/70fbaafc6078451cb23ec9e98b596777.png)









