Caeoon

Results 29 comments of Caeoon

这个真的学到了 ```c++ // 输入 n,打印 n 个 tab 缩进 void printIndent(int n) { for (int i = 0; i < n; i++) { printf(" "); } } ```

贴个C++的用哈希表的代码 ```cpp class Solution { public: bool isSubsequence(string s, string t) { // 二分查找 int m = s.size(), n = t.size(); // 将较长的字符串保存到map里去 unordered_map map_t(256); for(int i = 0; i...

1650题: 方法一:套模板 ```cpp class Solution { public: Node* lowestCommonAncestor(Node* p, Node * q) { // 区别:本题没有根节点 // 找到根节点 Node *parent = p; // 从p开始找起 while(parent->parent){ if(parent == q){ return parent;...

东哥,请问一下开头说的两篇文章(写了回文串和回文序列相关的问题)在哪里呀,在左侧栏和数组那篇都搜索了没搜到

优化了一下 拼车 ```cpp class Solution { public: bool carPooling(vector& trips, int capacity) { // 0

求二叉树最大深度这里:因为求二叉树最大深度的操作代码其实既可以写在后序位置也可以写在前序位置,我个人认为写在前序位置是求深度,而写在后序位置是求高度的。 因为若是写在后序位置,等于先一条道走到底,这时才返回叶子结点的'深度'为1,而这是不符合逻辑的。 ```cpp // 定义:输入根节点,返回这棵二叉树的最大深度 int maxDepth(TreeNode root) { if (root == null) { return 0; } // 利用定义,计算左右子树的最大深度 int leftMax = maxDepth(root.left); int rightMax = maxDepth(root.right); // 整棵树的最大深度等于左右子树的最大深度取最大值, //...

我看开头就想起了汉诺塔,但是这题用递归有些过于复杂了,用冒泡排序每次把最大值沉底应该会快一些