摘要:1、问题描述 Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contai
阅读全文
摘要:1、问题描述 Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following un
阅读全文
摘要:1、问题描述 Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally iden
阅读全文
摘要:1、问题描述 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
阅读全文
摘要:1、问题描述 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which t
阅读全文
摘要:1、问题描述 You need to find the largest value in each row of a binary tree. Example: 2、边界条件:root==null 3、思路:层级遍历,每一层找到最大值,记录 4、代码实现 5、api
阅读全文
摘要:1、问题描述 Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following un
阅读全文
摘要:1、二叉树 完全二叉树(complete binary tree):除了最下面一层都是满的,最下面一层也是优先排列在左边。这样的话父亲节点和孩子节点就在序号上面有关系: 父亲节点为n,那么子节点的编号为2n和2n+1。这样就可以操作序号来操作完全二叉树。 A1 / \ B2 C3 / \ / \ D
阅读全文
摘要:1、问题描述 Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: All root-to-leaf paths are: 2、边界条件:root为null;
阅读全文
摘要:1、问题描述 Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
阅读全文
摘要:1、问题描述 Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: The solution set must not contain duplic
阅读全文
摘要:1、问题描述 A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED repr
阅读全文
摘要:1、问题描述 Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where
阅读全文
摘要:1、问题描述: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, ret
阅读全文
摘要:1、问题描述: Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbe
阅读全文
摘要:1、链表数据结构 内存利用率高;动态分配 2、链表类定义 单向链表节点 public calss ListNode { int val =0; ListNode next = null; public void Node(int val_) { this.val = val_; this.next
阅读全文
摘要:1、例题--排列 Permutation Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2
阅读全文
摘要:1.Description Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may a
阅读全文
摘要:旋转链表函数 public ListNode reverse(ListNode head) { ListNode prev = null; while (head != null) { ListNode next = head.next; head.next = prev; prev = head;
阅读全文
摘要:1、题目描述 Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,
阅读全文
摘要:1、红黑树的限制条件 1)红黑树的节点是有颜色的,红色或者黑色 2)根节点是黑色的 3)每个叶子节点(叶节点即指树尾端NIL指针或NULL节点)是黑色的 4)如果一个节点是红色的,那么它的两个子节点都是黑色的;推论,不存在两个红色节点是相邻的。 5)从一个节点开始到每个叶子节点的简单路径上面的黑色节
阅读全文
摘要:1、二叉排序树删除节点P 假设节点P是节点F的左子树 1)节点P无子节点 直接删除,其他节点不动。 2)节点P只有左子节点Pl或者右子节点Pr 删除P,将Pl或者Pr挂载为F节点的左子树。如果P为F的右子树,则挂载为F的右子树。这样也不会破坏二叉排序树的特性(指排序的变化)。 3)节点P既有左子树P
阅读全文