摘要: 因为二叉搜索树的左子树<根<右子树的性质,按right-root-left的顺序遍历很容易求出累加和 阅读全文
posted @ 2019-09-24 11:35 dodoBehind 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 1 public boolean isSameTree(TreeNode p, TreeNode q) { 2 if (p==null&&q==null)return true; 3 if (p==null||q==null)return false; 4 return check(p, q); 5 } 6 7 ... 阅读全文
posted @ 2019-09-24 10:22 dodoBehind 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 1 boolean ans = false; 2 3 public boolean isSubtree(TreeNode s, TreeNode t) { 4 if (t == null) return true; 5 if (s == null) return false; 6 dfs(s, t); 7 ... 阅读全文
posted @ 2019-09-24 10:16 dodoBehind 阅读(124) 评论(0) 推荐(0) 编辑
摘要: HashMap底层是一个数组,通过允许冲突来实现大小可扩充。数组的下标是对象的散列码,存储的是list,查询list的时候是线性equals()比较(所以速度的瓶颈在于不能让list过长,也就是数据不能太集中)。 放入HashMap的对象要实现2个方法,hashCode()和equals()。 eq 阅读全文
posted @ 2019-09-24 09:51 dodoBehind 阅读(167) 评论(0) 推荐(0) 编辑