add: 230218

This commit is contained in:
Eatswap 2023-02-18 22:02:46 +08:00
parent 18ecf286e4
commit da93f6229e
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
2 changed files with 22 additions and 1 deletions

21
cpp/2302/230218.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <algorithm>
struct TreeNode {
int val;
TreeNode* left;
TreeNode* right;
explicit TreeNode(int x, TreeNode* left = nullptr, TreeNode* right = nullptr) : val(x), left(left), right(right) {}
};
/**
* 226. Invert Binary Tree
* Given the root of a binary tree, invert the tree, and return its root.
*/
class Solution {
public:
static TreeNode* invertTree(TreeNode* root) {
return root ? (std::swap(root->left, root->right), invertTree(root->left), invertTree(root->right), root) : nullptr;
}
};

View File

@ -16,7 +16,7 @@ ENDIF()
# Optimisation
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast -march=native -mtune=native -finline-functions -ffast-math -fomit-frame-pointer")
ADD_EXECUTABLE(leetcode-cpp main.cpp)
ADD_EXECUTABLE(leetcode-cpp main.cpp 2302/230218.cpp)
# ADD_SUBDIRECTORY(2112)
# ADD_SUBDIRECTORY(2201)