Giter VIP home page Giter VIP logo

leetcode's Issues

小白关于代码格式的问题请教

102 中的 10 行和 16 行

在有参宏定义时 #define 后接空格数量,第 10 行为一个,换行接四个。第 16 行为八个,换行接八个。

这样写是遵循了哪种规范?

小建议

能添加下简单的算法描述吗

add_two_sum have something wrong

You convert it to reverse order before adding, but the carry should be given to the previous one.for example:243+563->342+365=707. in your code it's 608

大神

我是C小白,不知道每个case要做什么😂

advice

Could you please give some annotations?Some codes are difficult to understand for me.

Implement Non-Recursive Inorder Traversal for LeetCode Problem #94 to Avoid Stack Overflow

The current implementation of bst_inorder_traversal.c uses a recursive method for inorder traversal, which may lead to a stack overflow in cases of deep recursion. To mitigate this issue, it is recommended to use an iterative approach with an explicit stack. This prevents excessive stack usage and enhances the program's robustness. Below is the improved code:

#include <stdio.h>
#include <stdlib.h>

struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};

struct Stack {
    struct TreeNode* node;
    struct Stack* next;
};

void push(struct Stack** stack, struct TreeNode* node) {
    struct Stack* new_node = (struct Stack*)malloc(sizeof(struct Stack));
    if (new_node == NULL) {
        exit(1);
    }
    new_node->node = node;
    new_node->next = *stack;
    *stack = new_node;
}

struct TreeNode* pop(struct Stack** stack) {
    if (*stack == NULL) {
        return NULL;
    }
    struct Stack* top = *stack;
    struct TreeNode* node = top->node;
    *stack = top->next;
    free(top);
    return node;
}

int isEmpty(struct Stack* stack) {
    return stack == NULL;
}

void inorderTraversal(struct TreeNode* root) {
    struct Stack* stack = NULL;
    struct TreeNode* current = root;

    while (current != NULL || !isEmpty(stack)) {
        while (current != NULL) {
            push(&stack, current);
            current = current->left;
        }
        current = pop(&stack);
        printf("%d ", current->val);
        current = current->right;
    }
}

This approach improves memory management and ensures the traversal can handle deeper trees without crashing.

求教

int multiply(int a, char *b) {
return a b;
}

我就想问这道算法题如何解,codewars 的 c 注册入门题目

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.