LetCode-103-이차나무의 톱니 모양 차원 - C 언어

1074 단어 LeetCode
/*
*     :
*  102    ,102   , i&1 != 0  ,    。
*
*
*/

#define LEV 1024
#define LEN 1024

typedef struct  TreeNode  Node;

void get(Node *node, int level, int **ret, int *ret_index, int *rcs){
    if(!node) return;
    
    if(!ret[level]){
        ret[level] = (int *)malloc(sizeof(int) * LEN);
        rcs[level] = 0;
    }
    
    if(level > *ret_index){
        *ret_index = level;
    }
    
     ret[level][rcs[level]++] = node->val; 
    
    get(node->left, level+1, ret, ret_index, rcs);
  
     get(node->right, level+1, ret, ret_index, rcs);
  
    
}

int** zigzagLevelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes){
    int **ret = (int **)malloc(sizeof(int*) * LEV);
    int *rcs = (int*)malloc(sizeof(int) * LEV);
    int ret_index = 0;
    int i, j, tmp, k;
    
    memset(ret, 0, sizeof(int*) * LEV);
    memset(rcs, 0, sizeof(int) * LEV);
    
    get(root, 0, ret, &ret_index, rcs);
    
    *returnSize = root==NULL ? 0 : ret_index+1;
    *returnColumnSizes = rcs;
    
    for(i=0; i

좋은 웹페이지 즐겨찾기