随笔分类 -  leetcode

摘要:101. 对称二叉树 (1过) 给定一个二叉树,检查它是否是镜像对称的。 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的: 说明: 如果你可以运用递归和迭代两种方法解决这个问题,会很加分。 我的层次遍历: 注意由于 阅读全文
posted @ 2019-03-26 11:12 twoheads 阅读(126) 评论(0) 推荐(0)
摘要:105. 从前序与中序遍历序列构造二叉树 (没思路,典型记住思路好做) 根据一棵树的前序遍历与中序遍历构造二叉树。 注意:你可以假设树中没有重复的元素。 例如,给出 返回如下的二叉树: 链接:https://www.nowcoder.com/questionTerminal/0ee054a8767c 阅读全文
posted @ 2019-03-25 17:12 twoheads 阅读(188) 评论(0) 推荐(0)
摘要:102. 二叉树的层次遍历 (1过,隐蔽错误花时间很多,简单题目本应很快,下次注意红色错误的地方) 给定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。 例如:给定二叉树: [3,9,20,null,null,15,7], 返回其层次遍历结果: 107. 二叉树的层次遍历 阅读全文
posted @ 2019-03-25 15:32 twoheads 阅读(173) 评论(0) 推荐(0)
摘要:(DFS思路对,写复杂了) 给定一个二维的矩阵,包含 'X' 和 'O'(字母 O)。 找到所有被 'X' 围绕的区域,并将这些区域里所有的 'O' 用 'X' 填充。 示例: 运行你的函数后,矩阵变为: 解释 被围绕的区间不会存在于边界上,换句话说,任何边界上的 'O' 都不会被填充为 'X'。 阅读全文
posted @ 2019-03-25 14:11 twoheads 阅读(283) 评论(0) 推荐(0)
摘要:给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。 说明:本题中,我们将空字符串定义为有效的回文串。 示例 1: 示例 2: 阅读全文
posted @ 2019-03-22 17:32 twoheads 阅读(164) 评论(0) 推荐(0)
摘要:(不会,经典广度优先搜索) 给定两个单词(beginWord 和 endWord)和一个字典,找到从 beginWord 到 endWord 的最短转换序列的长度。转换需遵循如下规则: 说明: 如果不存在这样的转换序列,返回 0。 所有单词具有相同的长度。 所有单词只由小写字母组成。 字典中不存在重 阅读全文
posted @ 2019-03-22 13:22 twoheads 阅读(255) 评论(0) 推荐(0)
摘要:不同的子序列 distinct-subsequences(hard) (忘了,典型) 给定一个字符串 S 和一个字符串 T,计算在 S 的子序列中 T 出现的个数。 一个字符串的一个子序列是指,通过删除一些(也可以不删除)字符且不干扰剩余字符相对位置所组成的新字符串。(例如,"ACE" 是 "ABC 阅读全文
posted @ 2019-03-22 10:51 twoheads 阅读(234) 评论(0) 推荐(0)
摘要:(没做出来,典型题目重要) 二叉树中的最大路径和(hard) 给定一个非空二叉树,返回其最大路径和。 本题中,路径被定义为一条从树中任意节点出发,达到任意节点的序列。该路径至少包含一个节点,且不一定经过根节点。 示例 1: 示例 2: 阅读全文
posted @ 2019-03-21 18:19 twoheads 阅读(848) 评论(0) 推荐(0)
摘要:给定一个未排序的整数数组,找出最长连续序列的长度。 要求算法的时间复杂度为 O(n)。 示例: 阅读全文
posted @ 2019-03-21 16:23 twoheads 阅读(118) 评论(0) 推荐(0)
摘要:(1AC) 给定一个二叉树,它的每个结点都存放一个 0-9 的数字,每条从根到叶子节点的路径都代表一个数字。 例如,从根到叶子节点路径 1->2->3 代表数字 123。 计算从根到叶子节点生成的所有数字之和。 说明: 叶子节点是指没有子节点的节点。 示例 1: 阅读全文
posted @ 2019-03-21 14:27 twoheads 阅读(238) 评论(0) 推荐(0)
摘要:(1 AC) 填充每个节点的下一个右侧节点指针 I是完美二叉树。这个是任意二叉树 给定一个二叉树 填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 next 指针设置为 NULL。 初始状态下,所有 next 指针都被设置为 NULL。 示例:For ex 阅读全文
posted @ 2019-03-21 14:17 twoheads 阅读(308) 评论(0) 推荐(0)
摘要:Pascal's triangle (1过) Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return 给定一个非负整数 numRows,生成杨辉三角的 阅读全文
posted @ 2019-03-20 18:35 twoheads 阅读(179) 评论(0) 推荐(0)
摘要:109. 有序链表转换二叉搜索树 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 给定一个单链表,其中的元素按升序排序,将其转换 阅读全文
posted @ 2019-03-20 15:47 twoheads 阅读(193) 评论(0) 推荐(0)
摘要:balanced-binary-tree (1过) Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a bin 阅读全文
posted @ 2019-03-20 10:58 twoheads 阅读(123) 评论(0) 推荐(0)
摘要:path-sum (1过) Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals th 阅读全文
posted @ 2019-03-19 17:41 twoheads 阅读(126) 评论(0) 推荐(0)
摘要:best-time-to-buy-and-sell-stock-i Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted t 阅读全文
posted @ 2019-03-19 11:01 twoheads 阅读(179) 评论(0) 推荐(0)
摘要:原题地址https://leetcode.com/problems/single-number-ii/ 题目描述Given an array of integers, every element appears three times except for one. Find that single 阅读全文
posted @ 2019-03-18 17:52 twoheads 阅读(205) 评论(0) 推荐(0)
摘要:原题地址https://leetcode.com/problems/single-number/ 题目描述Given an array of integers, every element appears twice except for one. Find that single one. 给出一 阅读全文
posted @ 2019-03-18 15:44 twoheads 阅读(200) 评论(0) 推荐(0)