• 【leetcode】94. 二叉树的中序遍历


    int* inorderTraversal(struct TreeNode* root, int* returnSize) {
        *returnSize = 0;
        int* res = malloc(sizeof(int) * 501);
        struct TreeNode** stk = malloc(sizeof(struct TreeNode*) * 501);
        int top = 0;
        while (root != NULL || top > 0) {
            while (root != NULL) {
                stk[top++] = root;
                root = root->left;
            }
            root = stk[--top];
            res[(*returnSize)++] = root->val;
            root = root->right;
        }
        return res;
    }
    void recursion(struct TreeNode* root, int* returnSize,int* arr){
        if(!root) return;
        recursion(root->left,returnSize,arr);
        arr[(*returnSize)++]=root->val;
        recursion(root->right,returnSize,arr);
    }
    int* inorderTraversal(struct TreeNode* root, int* returnSize){
        *returnSize=0;
        int* arr=(int*)calloc(1000,sizeof(int));
        recursion(root,returnSize,arr);
        return arr;
    }
  • 相关阅读:
    zabbix key 模样
    windows key代码
    windows更新代理地址配置
    Proftpd搭建
    SAS界面标题乱码
    jenkins-2.225部署
    DNS 安全详解
    DNS搭建
    修复linux登录超时问题
    prometheus安装全过程
  • 原文地址:https://www.cnblogs.com/ganxiang/p/14133474.html
Copyright © 2020-2023  润新知