iT邦幫忙

2025 iThome 鐵人賽

0

https://ithelp.ithome.com.tw/upload/images/20260122/20177944Ih3RUHuY3G.jpg

https://ithelp.ithome.com.tw/upload/images/20260122/20177944N49BoaCPtL.jpg

https://ithelp.ithome.com.tw/upload/images/20260122/20177944gUR4A4K09s.jpg

https://ithelp.ithome.com.tw/upload/images/20260122/20177944JoM583JtP9.jpg

https://ithelp.ithome.com.tw/upload/images/20260122/20177944gRcHi461k8.jpg

https://ithelp.ithome.com.tw/upload/images/20260122/20177944lwIcJmFjn0.jpg

https://ithelp.ithome.com.tw/upload/images/20260122/20177944SBsT8uQO9b.jpg

class Solution { //98. O(N)
public:
    bool isValidBST(TreeNode* root) {
        return dfs(root, nullptr, nullptr);
    }
    bool dfs(TreeNode* a, TreeNode* lo, TreeNode* hi) {
        if (!a) return true;

        if (lo && a->val <= lo->val) return false;
        if (hi && a->val >= hi->val) return false;
        return dfs(a->left, lo, a) && dfs (a->right, a, hi);
    }
};

上一篇
I have memorized 378 need some help
下一篇
First time to assist mock interview and push me memorized the problem 200 Number of Islands 13 March
系列文
轉職仔之Data Science and ai master後的持續精進技術之路38
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言