码迷,mamicode.com
首页 >  
搜索关键字:treenode    ( 1958个结果
LeetCode Path Sum 判断树的路径之和
1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(i...
分类:其他好文   时间:2014-11-08 21:58:27    阅读次数:179
LeetCode OJ Symmetric Tree 判断是否为对称树(AC代码)
1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(i...
分类:其他好文   时间:2014-11-05 14:42:43    阅读次数:179
二叉树遍历 非递归算法
mooc的作业本来以为是很简单,真正写下去才知道不简单。每个都略有技巧,细细琢磨#include #include int all, top;class TreeNode{ public: int value; TreeNode* left; Tree...
分类:编程语言   时间:2014-11-02 19:30:26    阅读次数:276
leetcode-Minimum Depth of Binary Tree
1 class Solution { 2 public: 3 int minDepth(TreeNode *root) { 4 if (root == nullptr) return 0; 5 if (root->left != nullptr&&root-...
分类:其他好文   时间:2014-10-29 12:08:21    阅读次数:153
leetcode-Construct Binary Tree from Preorder and Inorder Traversal
recursive 1 #include 2 #include 3 using namespace std; 4 5 struct TreeNode { 6 int val; 7 TreeNode *left; 8 TreeNode *right; 9 ...
分类:其他好文   时间:2014-10-29 10:20:20    阅读次数:199
leetcode Minimum Depth of Binary Tree
1,关于递归还是要有时间就练习,又有些生疏了/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeN...
分类:其他好文   时间:2014-10-28 07:02:47    阅读次数:141
对称树
闲着没事,做两道题玩玩,有一些地方还是有一些意思的;对称树 1 ```c++ 2 bool isSymmetric(TreeNode *root) 3 { 4 //约定空树是对称的 5 if(root==NULL) 6 return true; 7 else 8 return isEqual(roo...
分类:其他好文   时间:2014-10-27 22:48:22    阅读次数:333
Binary Tree Preorder Traversal
递归实现(python):# Definition for a binary tree nodeclass TreeNode: def __init__(self, x): self.val = x self.left = None self...
分类:其他好文   时间:2014-10-27 17:21:37    阅读次数:125
leetcode第一刷_Validate Binary Search Tree
有了上面的教训,这道题就简单多了,什么时候该更新pre是明白的了,倒是有个细节,二叉搜索树中是不同意有相等节点的,所以题目的要求用黑体字标明了。写的时候注意就能够了。class Solution {public: TreeNode *pre = NULL; bool isValidBST...
分类:其他好文   时间:2014-10-26 14:15:49    阅读次数:229
leetcode:Symmetric Tree
基础有待加强啊,由该题应发出来一些问题,现在来总结下。首先是二叉树的结构: struct TreeNode { EleType val; TreeNode *left; TreeNode *right; };然后是二叉树,先序遍历的构建方法,由于只有扩展后的二叉树可以做到一个...
分类:其他好文   时间:2014-10-23 19:04:53    阅读次数:171
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!