C语言 | Leetcode C语言题解之第530题二叉搜索树的最小绝对差

题目:

题解:

cpp 复制代码
void dfs(struct TreeNode* root, int* pre, int* ans) {
    if (root == NULL) {
        return;
    }
    dfs(root->left, pre, ans);
    if (*pre == -1) {
        *pre = root->val;
    } else {
        *ans = fmin(*ans, root->val - (*pre));
        *pre = root->val;
    }
    dfs(root->right, pre, ans);
}

int getMinimumDifference(struct TreeNode* root) {
    int ans = INT_MAX, pre = -1;
    dfs(root, &pre, &ans);
    return ans;
}
相关推荐
海石20 小时前
1500分的题目,确实有实力,不过还是我略胜一筹
算法·leetcode
海石20 小时前
【记忆化搜索】条条大路通AC,走好适合你的那一条,走到后再考虑走得快
算法·leetcode
gugucoding21 小时前
21. 【C语言】打包不同类型:结构体
c语言·开发语言
gugucoding1 天前
31. 【C语言】堆栈与队列的实现
c语言·开发语言·数据结构·链表
Yang_jie_031 天前
笔记:数据结构(C语言版)第一章知识点详细归纳
c语言·数据结构·算法
czhaii1 天前
串口1中断收发-C语言-MODBUS协议
c语言·开发语言
apihz1 天前
随机驾考题目(C 照科一 / 科四 2000+ 题)免费API调用教程
android·java·c语言·开发语言·网络协议·tcp/ip
三十岁老牛再出发1 天前
07.07.每日总结
c语言·windows·python
C++ 老炮儿的技术栈1 天前
MFC 自定义纯色居中文字进度条控件
c语言·数据库·c++·windows·算法·c·visual studio
tachibana21 天前
hot100 排序链表(148)
java·数据结构·算法·leetcode·链表