ICode9

精准搜索请尝试: 精确搜索
  • 方法判断两个数字是否相同2021-07-21 18:01:45

    package com.cnblogs.www;/*题目要求:定义一个方法,用来判断两个数字是否相同。 */public class Demo05 { public static void main(String[] args) { System.out.println(isSame(10,20));// false System.out.println(isSame(20,20));// true } /* 三要

  • 剑指offer26:树的子结构2021-04-27 12:33:17

    题目链接: https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/ 题目描述: 输入两棵二叉树A和B,判断B是不是A的子结构。(约定空树不是任意一个树的子结构) B是A的子结构, 即 A中有出现和B相同的结构和节点值。 例如: 给定的树 A:      3     / \    4   5  

  • 对称二叉树2021-04-05 15:05:32

    对称二叉树 根据上图可知:若满足对称二叉树,必须满足: 1. L->val == R->val 2. L->left->val == R->right->val 3. L->right->val == R->left->val 因此可以自顶向下,递归求解即可。 设置一个递归函数isSame(r1, r2),表示如果对称,返回true,否则返回false 递归终止条件:r1null

  • 「GDKOI2021普及组Day3」简要题解2021-01-30 20:33:06

    T1:三角形相似 题目大意:给定两个三角形,判断这两个三角形是否相似 题解: 直接根据点的坐标求出三边长,然后全排列枚举一下边匹配的关系 注意精度 Code #include<cmath> #include<cstdio> #include<cstring> #define db long double #define ll long long #define mxdb 1e-9 using

  • 572.另一个树的子树2020-05-07 11:52:06

    思路 核心思想 递归 首先寻找s,t具有相同的根节点的子树 p ,q 判断p 、q是否相同(判断两棵树是否相同) 代码 /* *7ms */ public boolean isSubTree(TreeNode s,TreeNode t){ if(t==null) return true;//t为null 一定是true if(s==null) return false;//此处t一定不为

  • p56 树t是否等于树s的子树 (leetcode 572)2020-03-18 17:09:57

    一:解题思路 方法一:将s中的每一颗子树都和t进行对比。Time:O(m*n),Space:O(h) 方法二:将s和t的每颗子树的根节点都设置一个哈希值,于是只需要对比对于节点的哈希值就行。Time:O(m+n),Space:O(m+n) 二:完整代码示例 (C++版和Java版) 方法一C++: class Solution { public: bool isSa

  • 方法重载2019-06-14 19:04:14

    什么是方法重载 方法重载:指在同一个类中,允许存在一个以上的同名方法,只要它们的参数列表不同即可,与修饰符和返回值类型无关。 参数列表不同是指参数的 个数不同 数据类型不同 顺序不同 重载方法调用 JVM通过方法的参数列表,调用不同的方法。 需求 比较两个数据是否相等。参数类型

  • LeetCode题解之 Subtree of Another Tree2019-03-02 09:53:41

    1、题目描述   2、问题分析 判断一个节点,然后判断子树。   3、代码 1 bool isSubtree(TreeNode* s, TreeNode* t) { 2 if (s == NULL) 3 return false; 4 else { 5 return isSame(s,t) || isSubtree(s->left, t) || isSubtree(s->right,

  • LeetCode572. Subtree of Another Tree2019-02-27 21:52:27

    572. Subtree of Another Tree Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node’s descendants. The tree

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有