add: noexcept

This commit is contained in:
Eatswap 2023-04-19 12:05:37 +08:00
parent 0ba5fb7cb8
commit f9f7f6929f
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
1 changed files with 7 additions and 7 deletions

View File

@ -15,20 +15,20 @@ struct TreeNode {
class Solution { class Solution {
private: private:
static inline constexpr int MAX(int x, int y) { return x > y ? x : y; } static inline constexpr int MAX(int x, int y) noexcept { return x > y ? x : y; }
static inline constexpr int MIN(int x, int y) { 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) { return x < 0 ? -x : x; } 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: 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; 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)); int ret = MAX(ABS(n->val - min), ABS(n->val - max));
const int min_ = MIN(min, n->val), max_ = MAX(max, n->val); const int min_ = MIN(min, n->val), max_ = MAX(max, n->val);
if (n->left) if (n->left)