![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
Alex Hwang
这个作者很懒,什么都没留下…
展开
-
Leetcode-面试题08.07-Permutation I
DescriptionWrite a method to compute all permutations of a string of unique characters.Exampleexample1:Input: S = "qwe"Output: ["qwe", "qew", "wqe", "weq", "ewq", "eqw"]example2:Input: S = "ab"Output: ["ab", "ba"]NoteAll charaters are English原创 2020-05-31 20:24:27 · 213 阅读 · 0 评论 -
Leetcode-101-Symmetric tree
DescriptionGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).ExampleFor example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3 But the following [1,2,2,null,3,nul原创 2020-05-31 14:55:34 · 143 阅读 · 0 评论 -
Leetcode-437 Path Su III
DescriptionYou are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nod原创 2020-05-30 22:32:18 · 122 阅读 · 0 评论 -
Leetcode-173 Binary-Search-Tree-Iterator
DescriptionImplement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Example:BSTIterator iterator = new BSTIterator(root);iterato原创 2020-05-29 13:37:42 · 125 阅读 · 0 评论 -
二叉树的一点心得
Leetcode二叉树刷题的一点心得最近一直在刷Leetcode的二叉树的题,所以就想写一篇博客来谈一谈心得。目前做到的大部分问题,都是可以用树的遍历来解决。而树的遍历,我觉得大体上可以分为三类做法:递归栈Morris遍历实际上前两种大家都非常熟悉,通过递归或者栈可以很好的实现对于树的三种遍历。而Morris遍历,实际上是一种空间复杂度非常低的操作,充分利用了叶节点空闲的指针。具体可以参考这篇文章。然后接下来就是一些做题技巧了:剪枝:我是一般会利用一个全局变量来进行剪枝的操作,避原创 2020-05-25 19:56:46 · 1047 阅读 · 0 评论 -
LeetCode(98)验证二叉搜索树
自己真的是太菜了,做了好多次都是WA。后来参考了官方题解。Description:给定一个二叉树,判断其是否是一个有效的二叉搜索树。假设一个二叉搜索树具有如下特征:节点的左子树只包含小于当前节点的数。节点的右子树只包含大于当前节点的数。所有左子树和右子树自身必须也是二叉搜索树。示例1:输入: 2 / \ 1 3输出: true示例2:输入: ...原创 2020-05-05 22:09:58 · 115 阅读 · 0 评论 -
LeetCode(338)比特位计数
(338)比特位计数Description:给定一个非负整数 num。对于 0 ≤ i ≤ num 范围中的每个数字 i ,计算其二进制数中的 1 的数目并将它们作为数组返回。示例1:输入: 2输出: [0,1,1]示例2:输入: 5输出: [0,1,1,2,1,2]思路:题要求使用一种O(N)的算法。那么这就很明了了,典型的动态规划。我们仔细分析题目不难发现:我们...原创 2020-02-14 19:35:27 · 139 阅读 · 0 评论 -
LeetCode(125)验证回文段
(125)验证回文段Description:给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。**说明:**本题中,我们将空字符串定义为有效的回文串。示例1:输入: "A man, a plan, a canal: Panama"输出: true示例2:输入: "race a car"输出: false思路:其实整体思路也是首先将...原创 2020-02-12 18:59:41 · 220 阅读 · 0 评论 -
LeetCode(88)合并两个有序数组
(88)合并两个有序数组Description:给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中*,*使得 num1 成为一个有序数组。说明:初始化 nums1 和 nums2 的元素数量分别为 m 和 n。你可以假设 nums1 有足够的空间(空间大小大于或等于 m + n)来保存 nums2 中的元素。示例:输入:nums1 =...原创 2020-02-12 18:58:09 · 139 阅读 · 0 评论 -
LeetCode(111)二叉树的最小深度
(111)二叉树的最小深度Description:给定一个二叉树,找出其最小深度。最小深度是从根节点到最近叶子节点的最短路径上的节点数量。说明:叶子节点是指没有子节点的节点。示例:给定二叉树 [3,9,20,null,null,15,7], 3/ \9 20 / \15 7返回它的最小深度 2.思路:其实很简单,大致思路就是喝求最大深度相反。不...原创 2020-02-12 18:56:19 · 114 阅读 · 0 评论 -
LeetCode(771)宝石与石头
(771)宝石与石头Description:给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头。 S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石。J 中的字母不重复,J 和 S中的所有字符都是字母。字母区分大小写,因此"a"和"A"是不同类型的石头。示例1:Input: J = "aA", S = "aAAbbbb"Output: 3...原创 2020-02-12 18:55:26 · 84 阅读 · 0 评论 -
LeetCode(959)由斜杠划分区域
LeetCode(959)由斜杠划分区域Description:在由 1 x 1 方格组成的 N x N 网格 grid 中,每个 1 x 1 方块由 /、\ 或空格构成。这些字符会将方块划分为一些共边的区域。(请注意,反斜杠字符是转义的,因此 \ 用 “\” 表示。)。返回区域的数目。示例1:输入:[" /","/ "]输出:2示例2:输入:[" /",...原创 2020-02-12 18:52:28 · 316 阅读 · 0 评论