add: 230218
This commit is contained in:
parent
18ecf286e4
commit
da93f6229e
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue