提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
LeetCodeDay15二叉树
LeetCode222.完全二叉树的节点数
class Solution {
public:
int countNodes(TreeNode* root) {
if(!root)return 0;
else{
return 1 + countNodes(root->left) + countNodes(root->right);
}
}
};
LeetCode110.平衡二叉树
class Solution {
public:
bool isBalanced(TreeNode* root) {
if(!root)return true;
else{
if(abs(maxDepth(root->left) - maxDepth(root->right)) > 1)
return false;
else
return isBalanced(root->left) && isBalanced(root->right);
}
}
int maxDepth(TreeNode* root){
if(!root)return 0;
else{
return 1 + max(maxDepth(root->left),maxDepth(root->right));
}
}
};
示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。
LeetCode257.二叉树的所有路径
class Solution {
public:
vector<string> binaryTreePaths(TreeNode* root) {
vector<string> result;
string path = "";
constructPath(root, path, result);
return result;
}
void constructPath(TreeNode* root, string path, vector<string>&result){
if(root != nullptr){
path += to_string(root->val);
if(root->left == nullptr && root->right == nullptr){
result.push_back(path);
}else{
path += "->";
constructPath(root->right, path, result);
constructPath(root->left, path, result);
}
}
}
};
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。
121

被折叠的 条评论
为什么被折叠?



