From f9f7f6929fd8da2fd6bc9d4d33e1141f3cd3ab70 Mon Sep 17 00:00:00 2001 From: Eatswap Date: Wed, 19 Apr 2023 12:05:37 +0800 Subject: [PATCH] add: noexcept --- cpp/2304/230418-CN.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cpp/2304/230418-CN.cpp b/cpp/2304/230418-CN.cpp index 0c1cd74..1af82be 100644 --- a/cpp/2304/230418-CN.cpp +++ b/cpp/2304/230418-CN.cpp @@ -15,20 +15,20 @@ struct TreeNode { class Solution { private: - static inline constexpr int MAX(int x, int y) { return x > y ? x : y; } - static inline constexpr int MIN(int x, int y) { return x < y ? x : y; } - static inline constexpr int ABS(int x) { return x < 0 ? -x : x; } + static inline constexpr int MAX(int x, int y) noexcept { return x > y ? x : y; } + static inline constexpr int MIN(int x, int y) noexcept { return x < y ? x : y; } + static inline constexpr int ABS(int x) noexcept { return x < 0 ? -x : x; } - static int dfs(TreeNode*, int, int); + static int dfs(TreeNode*, int, int) noexcept; public: - static int maxAncestorDiff(TreeNode*); + static int maxAncestorDiff(TreeNode*) noexcept; }; -int Solution::maxAncestorDiff(TreeNode* r) { +int Solution::maxAncestorDiff(TreeNode* r) noexcept { return r ? dfs(r, r->val, r->val) : 0; } -int Solution::dfs(TreeNode* n, int min, int max) { +int Solution::dfs(TreeNode* n, int min, int max) noexcept { int ret = MAX(ABS(n->val - min), ABS(n->val - max)); const int min_ = MIN(min, n->val), max_ = MAX(max, n->val); if (n->left)