首页 > TAG信息列表 > LeetCode101

leetcode101_对称二叉树

class Solution { public boolean isSymmetric(TreeNode root) { if(root == null) return true; return judge(root.left, root.right); } private boolean judge(TreeNode left, TreeNode right) { if(left == null && right =

LeetCode101.对称二叉树

LeetCode101.对称二叉树 题目:给定一个二叉树,检查它是否是镜像对称的。 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。但是 [1,2,2,null,3,null,3] 则不是镜像对称的: 思路:等价于检查root的左子树和右子树是不是对称,对于左右子树的每个节点一一比较即可,比较包括节点的值,以及对应子节点是

LeetCode101学习笔记-9.8

647. Palindromic Substrings 1 class Solution { 2 public: 3 int countSubstrings(string s) { 4 int ans=0; 5 for(int i=0;i<s.length();i++){ 6 ans+=extendSubstrings(s,i,i); 7 ans+=extendSubstrings(s,i,i+1

Leetcode101.对称二叉树

Leetcode101.对称二叉树 题目描述 给定一个二叉树,检查它是否是镜像对称的。 思路分析 二叉树,及每一个节点的子节点不超过两个 题目要求检查一个二叉树是否是镜像对称的,及要检查它本身及其它的每一个子节点是否也镜像对称 因此可以使用递归的思路 递归的遍历每一个节点,判断与其

leetcode101汇总

第2章—最易懂的贪心算法 2.2 分配问题 455.分发饼干 135 分发糖果 2.3 区间问题 435 无重叠区间 605 种花问题 452 用最少数量的箭引爆气球 763 划分字母区间 122 买卖股票的最佳时机II 406 根据身高重建队列 665 非递减数列 第3章—玩转双指针 3.2 两个数的问题 167 两数之

leetcode101.对称二叉树

101. 对称二叉树 这题算简单???我觉得中等不过分 迭代法,BFS class Solution { public boolean isSymmetric(TreeNode root) { Queue<TreeNode> queue = new LinkedList<>(); //空树或者只有一个root if(root == null || (root.left == null && root.r

每日一道leetcode101. 对称二叉树

每日一道leetcode101. 对称二叉树 2021.07.22 给定一个二叉树,检查它是否是镜像对称的。 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的: 1 / \ 2 2 \ \

leetcode101-一切皆可搜索

一切皆可搜索 一切皆可搜索深度遍历搜索leetcode695leetcode547leetcode417 回溯法leetcode46leetcode 77 一切皆可搜索 深度遍历搜索 深度优先搜索(depth-first seach,DFS)在搜索到一个新的节点时,立即对该新节点进行遍历;因此遍历需要用先入后出的栈来实现,也可以通过与栈

【二叉树 2.1】leetcode101. 对称二叉树(和翻转二叉树很相似,但是不同)

  文章目录 问题:101. 对称二叉树 解法1:递归法 递归三部曲 递归算法(两个后序遍历) 解法2:迭代法 解法3:使用栈 总结   问题:101. 对称二叉树 给定一个二叉树,检查它是否是镜像对称的。 核心:判断对称二叉树要比较的是哪两个节点,要比较的可不是左右节点!即对于二叉树是否对称,要

Leetcode101.对称二叉树

101.对称二叉树 给定一个二叉树,检查它是否是镜像对称的。 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的: 1 / \ 2 2 \ \ 3 3 进阶: 你可以运用递归和迭代两种方

[二叉树]leetcode101:对称二叉树(easy)

题目: 题解1:递归法 class Solution { public: /*解法1:递归法*/ bool isSymmetric(TreeNode* root){ if(root==nullptr)return true; return ismirror(root->right,root->left); } bool ismirror(TreeNode* p,TreeNode* q){ if(!p&

leetcode101_Symmetric Tree

LeetCode 101. Symmetric Tree (对称树) Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3   But the following