树相关题目套路: 先序 中序 后序 DFS其他遍历方式(如右左根) 层序遍历 if (!root) xxx; //应对只有左子树或只有右子树的情况 if (!root->left && !root-…
分类:LeetCode
[剑指offer] 数组中只出现一次的数字
本文首发于我的个人博客:尾尾部落 题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了偶数次。请写程序找出这两个只出现一次的数字。 解题思路 法一:大家都能想到的HashMap法 法二:异或法 任何一个数字异或它…
2018-05-17 101. Symmetric Tree
题意:给你一棵树,判断这棵树是不是关于中心线对称的。 解题思路: 如果根节点为NULL,返回true。 如果根节点不为空,查看根节点的左子树与右子树是否对称,这时需重载本函数,参数变为两个指针。 如果这两个指针至少有一个…
[LeetCode] Balanced Binary Tree 平衡二叉树
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tre…
[LeetCode] Most Frequent Subtree Sum 出现频率最高的子树和
Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a nod…
[LeetCode] Longest Line of Consecutive One in Matrix 矩阵中最长的连续1
Given a 01 matrix M, find the longest line of consecutive one in the matrix. The line could be hor…
LeetCode | Valid Palindrome
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cas…
LeetCode 162 Find Peak Element
题目描述 A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ num[…
279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ……
[Leetcode] Populating Next Right Pointers in Each Node 二叉树Next指针
Populating Next Right Pointers in Each Node I Given a binary tree struct TreeLinkNode { TreeLinkNode *left; Tr…
【leetcode】88. Merge Sorted Array 有序数组的merge
1. 题目 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You ma…
力扣(LeetCode)72
题目地址:https://leetcode-cn.com/probl…题目描述:给定两个单词 word1 和 word2,计算出将 word1 转换成 word2 所使用的最少操作数 。 你可以对一个单词进行…