码迷,mamicode.com
首页 >  
搜索关键字:hdoj tree    ( 20544个结果
[leetcode]_Binary Tree Inorder Traversal
题目:二叉树的中序遍历。思路:用递归来写中序遍历非常简单。但是题目直接挑衅说,----->"Recursive solution is trivial"。好吧。谁怕谁小狗。递归代码: 1 List inOrder = new ArrayList(); 2 3 public ...
分类:其他好文   时间:2014-06-29 12:55:36    阅读次数:176
【HDOJ】1501 Zipper
DFS。注意剪枝,0ms。 1 #include 2 #include 3 4 #define False 0 5 #define True 1 6 #define MAXN 201 7 8 char stra[MAXN], strb[MAXN], strc[MAXN=e3-e2-1; -...
分类:其他好文   时间:2014-06-29 12:35:06    阅读次数:193
Binary Tree Inorder Traversal
题目 Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 2 / 3 return [1,3,2]. Note: Recur...
分类:其他好文   时间:2014-06-20 10:22:00    阅读次数:221
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. 方法 根据树的中序遍历和后序遍历,来恢复树,使用递归的思想。 Tr...
分类:其他好文   时间:2014-06-07 14:50:37    阅读次数:231
LeetCode --- Validate Binary Search Tree
题目链接判断一颗二叉树是否是二叉搜索树(二叉排序树),也就是BST如果该二叉树是BST, 那么对其中序遍历,所得序列一定是单调递增的(不考虑有重复数值的情况)附上代码: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 *...
分类:其他好文   时间:2014-06-07 11:28:18    阅读次数:254
【HDOJ】1518 Square
DFS+剪枝。与HDOJ 1455如出一辙。 1 #include 2 #include 3 #include 4 5 #define MAXN 25 6 7 int nums[MAXN], n, len, cnt; 8 char visit[MAXN]; 9 10 int comp(co...
分类:其他好文   时间:2014-06-07 07:23:07    阅读次数:201
【HDOJ】1421 搬寝室
DP。这题都能TLE,发现memset有时居然比for还要慢。 1 #include 2 #include 3 #include 4 5 #define MAXN 2005 6 #define INF 0x3fffffff 7 int dp[MAXN][MAXN]; 8 int buf[M...
分类:其他好文   时间:2014-06-05 20:01:32    阅读次数:381
leetcode--Maximum Depth of Binary Tree
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 le...
分类:其他好文   时间:2014-06-05 14:10:38    阅读次数:304
leetcode--Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe...
分类:其他好文   时间:2014-06-05 13:42:24    阅读次数:264
leetcode--Populating Next Right Pointers in Each Node II
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 stil...
分类:其他好文   时间:2014-06-05 13:26:37    阅读次数:335
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!