上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 28 下一页
摘要: int maxDepth(TreeNode* root) { if (!root) return 0; int left = maxDepth(root->left); int right = maxDepth(root->right); // 返回二叉树的深度 // 只要当前节点不为空,深度至少都 阅读全文
posted @ 2022-10-08 11:22 YaosGHC 阅读(24) 评论(0) 推荐(0)
摘要: 起因是我做笔试,要写出所有子序列并做条件判断,我以为是回溯改一改,但事实上完全不是这样的 直达链接 主要是1,利用二进制序列枚举快速生成所有的可能子序列,然后利用哈希算法对数组去重(这个哈希算法可以直接背) vector<int> temp; vector<vector<int>> res; uno 阅读全文
posted @ 2022-09-29 16:44 YaosGHC 阅读(30) 评论(0) 推荐(0)
摘要: public class Test{ public static void main(String[] args) { System.out.println(new A()); } } class A{ @Override public String toString() { return "hel 阅读全文
posted @ 2022-09-29 11:42 YaosGHC 阅读(27) 评论(0) 推荐(0)
摘要: public static void main(String[] args) { List<String> allElements = List.of("a","b","c","d","e","f"); List<String> allList = new ArrayList<>(allElemen 阅读全文
posted @ 2022-09-25 15:27 YaosGHC 阅读(31) 评论(0) 推荐(0)
摘要: 已经知道的,字符串直接量会采用字符串常量池 new String会创建一个新的对象并分配内存地址 所以他俩==返回是false 我起初是不知道这个intern()方法是干嘛的 intern()方法返回字符串对象的规范化表示形式 从字符串常量池中查询当前字符串是否存在,若不存在就会将当前字符串放入常量 阅读全文
posted @ 2022-09-25 12:22 YaosGHC 阅读(25) 评论(0) 推荐(0)
摘要: public static void main(String[] args) { System.out.println(test()); } public static int test(){ int a= 1; try{ a=2/0; return a; }catch (Exception e){ 阅读全文
posted @ 2022-09-25 11:52 YaosGHC 阅读(20) 评论(0) 推荐(0)
摘要: public static void main(String[] args) { String s=""; System.out.println(s==null); int[] arr = new int[]{}; System.out.println(arr==null); List<Intege 阅读全文
posted @ 2022-09-25 11:35 YaosGHC 阅读(23) 评论(0) 推荐(0)
摘要: 京东笔试,总体难度比较低,但是最后一道我做不来 这题如果有思路应该不难,我觉得应该是动态规划相关的 题目 题目长这样 我又看到力扣有这种博弈类型的题目,我觉得这是我的盲区,应该补一下短板 阅读全文
posted @ 2022-09-24 21:13 YaosGHC 阅读(15) 评论(0) 推荐(0)
摘要: 直达链接 直观的想法:我可以遍历并重建,但也很明显效率低下,可能达到O(N2),但或许可能拿来当作练习,检查自己遍历/重建二叉树的基本功 不过现在先想想有没有效率更高的解法,我觉得重点应该是修改节点的两个指针 简单地画图分析后,我认为: 对于有两个孩子节点的节点,只需要将其左右孩子指针互换 对于只有 阅读全文
posted @ 2022-09-24 18:46 YaosGHC 阅读(34) 评论(0) 推荐(0)
摘要: 小米2020的秋招笔试卷遇到了 n个节点可以构成多少不同的二叉搜索树? f(1) = 1 f(2) = f(1) + f(1) f(3) = f(2) + f(1)*f(1) + f(2) … … 由此,我们可以得到递推式: f(n) = f(n-1) + f(n-2)\*f(1) + … + f( 阅读全文
posted @ 2022-09-24 17:41 YaosGHC 阅读(37) 评论(0) 推荐(0)
上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 28 下一页