- 博客(56)
- 收藏
- 关注
原创 极客时间java高级(第二次课程)
占用区域最大(占地盘的王者)垃圾回收的主要内存区域(垃圾收集器的主要治理对象)JDK各版本不断迭代区域划分,只为了更好更快地回收管理此区域各线程公用空间(对比虚拟机栈)
2022-09-03 23:18:10
4893
原创 求对应n字节的格雷码数组
题目描述 The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the seque...
2019-02-18 22:18:02
250
转载 把从1到n的所有情况构成的二叉搜索树添加到队列中
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3 ...
2019-01-26 00:59:56
503
转载 判断一个二叉树是不是二叉搜索树
package niuke.day1;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 contains only nodes with keys less than ...
2019-01-25 01:22:59
285
转载 二叉搜索树中有两个位置错位了,需要重新修正
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n ) space is pretty straight forward. Could you devise a ...
2019-01-24 21:37:26
439
原创 按之形顺序打印二叉树
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tre...
2019-01-11 23:10:16
248
原创 construct-binary-tree-from-inorder-and-postorder-traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.package leetcode;public class Construct_binary_tree_from...
2019-01-09 21:51:26
275
原创 二叉树的层序遍历(但是从下到上的放到数组中)
package niuke.day1;import java.util.ArrayList;import java.util.LinkedList;import java.util.Queue;import java.util.Stack;public class Binary_tree_level_order_traversal_ii { public static v...
2018-12-20 22:48:48
923
转载 二叉树的每一层横向节点用next连接(进阶版)
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extra ...
2018-12-19 21:58:26
397
原创 判断二叉树是否是镜像
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3 But the follo...
2018-12-19 19:11:10
735
原创 二叉树的层序遍历
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \...
2018-12-17 21:14:36
365
1
原创 判断平衡二叉树
package leetcode;public class Balanced_binary_tree { public static void main(String[] args) { } public boolean isBalanced(TreeNode root) { if(root == null) { ...
2018-12-17 16:19:39
191
原创 统计1-n的数目元素作为节点的树的种类个数
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ ...
2018-12-17 15:40:30
325
原创 判断两个二叉树是否是相同的二叉树
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 identical and the nodes have the same value. package lee...
2018-12-16 21:21:08
688
原创 把二叉树的每一层的节点进行横向连接
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node. If...
2018-12-16 18:39:10
488
1
原创 求二叉树的最大深度
package leetcode;/*Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.*/public class M...
2018-12-16 15:08:36
332
原创 二叉树--求出所有路径,它们的和是给定的数值
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ ...
2018-12-15 22:06:17
343
原创 从左上角走到右下角的走法数量(中间有障碍)
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as1and0respectively in the grid.For...
2018-12-10 13:02:22
2417
原创 从方格左上角到右下角的走法
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo...
2018-12-09 22:27:35
2086
原创 数字字符串对应解码方式
package leetcode;/*A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, d...
2018-12-09 20:58:48
2739
原创 判断二叉树的路径和是否和给定数值相等
package niuke.day1;import java.util.Stack;/*Given a binary tree and a sum, determine if the tree has a root-to-leaf path suchthat adding up all the values along the path equals the given sum.For ...
2018-12-06 22:47:35
421
原创 m*n矩阵从左上角到右下角的路径最小和
package leetcode;/*Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move eith...
2018-12-05 16:56:18
2550
原创 triangle
package leetcode;/*Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2],...
2018-12-05 15:42:49
230
原创 爬台阶问题(每一次爬一阶台阶,或者每一次爬二阶台阶)
package leetcode;/*You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?*///为了节省程序的时间...
2018-12-04 22:34:20
3325
原创 根节点到叶子节点的和值(根节点逐步升位)
package leetcode;/*Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number12...
2018-12-04 16:32:20
1284
原创 二叉树的前序遍历(迭代)
package leetcode;/*Given a binary tree, return the preorder traversal of its nodes' values*/import java.util.ArrayList;public class Binary_tree_preorder_traversal { public static void main...
2018-12-03 22:20:14
436
原创 后序遍历二叉树
package leetcode;/*Given a binary tree, return the postorder traversal of its nodes' values.*/import java.util.ArrayList;public class Binary_tree_postorder_traversal { public static void mai...
2018-12-03 22:10:27
174
原创 求二叉树的最小深度
package leetcode;/*Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.*/public class Min...
2018-12-03 19:29:44
435
原创 序列化二叉树
package niuke;/*题目描述:请实现两个函数,分别用来序列化和反序列化二叉树 思路:二叉树的序列化就是按照某种顺序遍历二叉树,遇到空结点是在遍历输出序列中 加入某个特殊字符进行标识,反序列化就是按照同样的规则将一个序列还原为一颗二叉树。 这里采用前序遍历的顺序进行序列化*/public class SortNumber { static String st...
2018-11-28 21:14:32
171
转载 复杂链表的复制
package niuke;import java.util.Random;@SuppressWarnings("unused")public class ClonRandomListNode { /*输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点, 另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。 (注意,输出结果中...
2018-11-28 12:58:47
108
转载 二叉树中和为某一值的路径
package niuke;import java.util.ArrayList;public class SumRoute { /*输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。 路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。 (注意: 在返回值的list中,数组长度大的数组靠前)*/ Arr...
2018-11-27 21:13:31
145
原创 滑动窗口的最大值
package niuke;import java.util.ArrayList;/*给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值。例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4,6,6,6,5}; 针对数组{2,3,4,2,6,2,5,1}的滑动窗口有以下6个:{[2,3,4],2,6,2,...
2018-11-26 18:07:51
230
原创 机器人的运动范围
package niuke;/*地上有一个m行和n列的方格。一个机器人从坐标0,0的格子开始移动,每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标和列坐标的数位之和大于k的格子。 例如,当k为18时,机器人能够进入方格(35,37),因为3+5+3+7 = 18。但是,它不能进入方格(35,38),因为3+5+3+8 = 19。请问该机器人能够达到多少个格子?*/pub...
2018-11-26 15:40:16
134
原创 扑克牌顺子
package niuke;/*LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到的话,他决定去买体育彩票,嘿嘿!!“红心A,黑桃3,小王,大王,方片5”,“Oh My God!”不是顺子.....LL不高兴了,他想了想,决定大\小 王可以看成任何数字,并且A...
2018-11-25 22:06:40
214
原创 最小的K个数
package niuke;import java.util.ArrayList;public class LittleNumber { /*输入n个整数,找出其中最小的K个数。例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,。*/ public static void main(String[] args) { ...
2018-11-25 21:20:33
117
原创 二叉搜索树的后序遍历序列
package niuke;/*输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。*/public class VerifySquenceOfBST { public static void main(String[] args) { int[] a = {1,2,3,4,5}...
2018-11-23 17:04:59
112
转载 二叉搜索树的后序遍历序列
/*输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。*/package niuke;import java.util.ArrayList;import java.util.Stack;public class KthNode { static int k = 6; publ...
2018-11-23 15:24:38
126
转载 表示数值的字符串
package niuke;public class NumberString { public static void main(String[] args) { System.out.println(isNumeric("1.2.3".toCharArray())); } public static boolean isNumeric(char[...
2018-11-22 21:37:11
112
转载 重建二叉树
package niuke;public class RebuildTreee { /*输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。 例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。*/ public static voi...
2018-11-22 20:16:56
103
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人