随笔分类 -  leetcode

上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 19 下一页
摘要:问题: 求给定二叉树的最短深度。 Example 1: Input: root = [3,9,20,null,null,15,7] Output: 2 Example 2: Input: root = [2,null,3,null,4,null,5,null,6] Output: 5 Constra 阅读全文
posted @ 2021-01-01 09:35 habibah_chang
摘要:问题: 给一个 N×N 的棋盘,可放置 N 个皇后,使得它们不能互相攻击。 PS:皇后可以攻击同一行、同一列、左上左下右上右下四个方向的任意单位。 Example 1: Input: n = 4 Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q... 阅读全文
posted @ 2020-12-29 14:50 habibah_chang
摘要:关联问题:排列1:46. Permutations, 排列2:47. Permutations II,组合:77. Combinations 问题: 给定一个数组,求对该数组进行全排列的所有结果。 Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[ 阅读全文
posted @ 2020-12-29 14:02 habibah_chang
摘要:问题: 给定一颗BST(二叉搜索树),其中存在两个节点顺序颠倒,请找出他们,并恢复正确次序。 Example 1: Input: root = [1,3,null,null,2] Output: [3,1,null,null,2] Explanation: 3 cannot be a left ch 阅读全文
posted @ 2020-12-05 12:20 habibah_chang
摘要:参考:labuladong 问题: 判断一个链表,是否为回文链表。 Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true 解法: 解法一:Linked List Traverse 链表遍历(后序遍 阅读全文
posted @ 2020-11-22 09:41 habibah_chang
摘要:问题: 给定一个字符串,求最少添加几个字母,能使的字符串成为回文字符串。 Example 1: Input: s = "zzazz" Output: 0 Explanation: The string "zzazz" is already palindrome we don't need any i 阅读全文
posted @ 2020-11-15 12:20 habibah_chang
摘要:问题: 给定k个有序链表,将这些链表的所有节点排序,组合成一个新的有序链表。 Example 1: Input: lists = [[1,4,5],[1,3,4],[2,6]] Output: [1,1,2,3,4,4,5,6] Explanation: The linked-lists are: 阅读全文
posted @ 2020-10-25 10:44 habibah_chang
摘要:问题: 给定一棵二叉树,对所有节点为root的子树,若存在重复的子树。将该节点加入res。 Example 1: Input: root = [1,2,3,4,null,2,4,null,null,4] Output: [[2,4],[4]] Example 2: Input: root = [2, 阅读全文
posted @ 2020-10-18 16:29 habibah_chang
摘要:124. Binary Tree Maximum Path Sum 问题: 求出给定二叉树中,最大路径和(节点权值相加)。(至少包含树中一个节点) Example 1: Input: [1,2,3] 1 / \ 2 3 Output: 6 Example 2: Input: [-10,9,20,nu 阅读全文
posted @ 2020-10-04 11:42 habibah_chang
摘要:参考:labuladong 递归反转链表的一部分 labubadong 如何k个一组反转链表 问题: 206.链表反转。 Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL 92.指定区间链表反转。 Note: 1 ≤ m 阅读全文
posted @ 2020-10-01 20:55 habibah_chang
摘要:Binary Search Tree 二叉搜索树问题。 遍历框架: 1 void BST(TreeNode root, int target) { 2 if (root.val == target) 3 // 找到目标,做点什么 4 if (root.val < target) 5 BST(root 阅读全文
posted @ 2020-10-01 14:15 habibah_chang
摘要:问题: 判断一颗二叉树是否为二叉搜索树。 解法:Binary Tree(二叉树) 首先,了解 二叉搜索树BST的定义: A binary search tree is a rooted binary tree whose internal nodes each store a key greater 阅读全文
posted @ 2020-10-01 13:57 habibah_chang
摘要:问题: 计算给定完全二叉树的节点个数。 Example: Input: 1 / \ 2 3 / \ / 4 5 6 Output: 6 解法:Complete Binary Tree(完全二叉树) 首先明确以下定义: (了解即可)Full Binary Tree 国际定义的 满二叉树 定义:A bi 阅读全文
posted @ 2020-09-30 08:03 habibah_chang
摘要:问题: 给出一颗二叉树,两个节点p和q,求出这两节点的最近公共父节点(LCA)。 Example 1: Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1 Output: 3 Explanation: The LCA of nodes 阅读全文
posted @ 2020-09-28 16:19 habibah_chang
摘要:问题: 实现下面两个转换: TreeNode* -> string string -> TreeNode* Example 1: Input: root = [1,2,3,null,null,4,5] Output: [1,2,3,null,null,4,5] Example 2: Input: r 阅读全文
posted @ 2020-09-26 18:30 habibah_chang
摘要:654. Maximum Binary Tree 问题: 用给定的数组,构成最大二叉树。 从数组中找到最大值,作为root,其index以左,作为左子树。index以右,作为右子树。 Example 1: Input: [3,2,1,6,0,5] Output: return the tree ro 阅读全文
posted @ 2020-09-26 14:02 habibah_chang
摘要:问题: 拉平二叉树 -> 只有right分支的链表。 For example, given the following tree: 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6 解法: 阅读全文
posted @ 2020-09-22 11:26 habibah_chang
摘要:二叉树 Binary Tree -【两棵树 对比】 问题: 给定 层序遍历的数组 表示二叉树。 100. 判断两棵二叉树是否相同。 Example 1: Input: 1 1 / \ / \ 2 3 2 3 [1,2,3], [1,2,3] Output: true Example 2: Input 阅读全文
posted @ 2020-09-19 15:32 habibah_chang
摘要:二叉树 Binary Tree -【一棵树 内部求最值or求和】 问题: 给定 层序遍历的数组 表示二叉树。 ⚠️ 注意:leaf节点:既无左孩子,又无右孩子 104:求二叉树的最深层数 Example: Given binary tree [3,9,20,null,null,15,7], 3 / 阅读全文
posted @ 2020-09-19 12:11 habibah_chang
摘要:参考:经典动态规划:打家劫舍系列问题 问题: base题目: 给定一组数列,代表一排住宅,各自能偷出的钱数。 不能偷取相邻的两家。求能偷出的最大钱数。 I base题目 Example 1: Input: nums = [1,2,3,1] Output: 4 Explanation: Rob hou 阅读全文
posted @ 2020-09-18 10:48 habibah_chang

上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 19 下一页