树
stloztoeplitz
严格标准不抱怨,宽松要求自提高
展开
-
binary-tree-level-order-traversal
题目没什么说的就是树的层次遍历,但是要考虑树为空的情况。而且对于Vector必须是先申请一个小Vector,对其操作完成后再将其加入大的Vector中。不能V[i].push_back(),因为这时候V[i]还不存在。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left原创 2016-12-22 20:32:39 · 233 阅读 · 0 评论 -
1002. 计算二叉查找树的高度
devcpp代码名字如果太相近就会出现bug#include <iostream>using namespace std;const int maxn = 100;int a[maxn],b[maxn];struct TreeNode { int val; TreeNode* left,*right; TreeNode(int a):val(a),left(NULL)原创 2016-12-30 15:14:21 · 563 阅读 · 0 评论 -
validate-binary-search-tree
while写成if debug了半天。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }原创 2016-12-28 10:32:41 · 263 阅读 · 0 评论 -
binary-tree-zigzag-level-order-traversal
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */vector<TreeNo原创 2016-12-27 12:33:08 · 267 阅读 · 0 评论 -
convert-sorted-list-to-binary-search-tree
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//** * Definition for binary tree * struc原创 2016-12-27 11:27:18 · 330 阅读 · 0 评论 -
path-sum-ii
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */vector<vector原创 2016-12-27 10:39:31 · 272 阅读 · 0 评论 -
sum-root-to-leaf-numbers
c++中各类类型与string类型的相互转化http://www.cnblogs.com/nzbbody/p/3504199.html 这道题还是坑了我这么久,一是忘了保留多种可能性,二是忘记了出来多个0的情况。后来用string来处理的确是方便了许多。/** * Definition for binary tree * struct TreeNode { * int val; *原创 2016-12-24 13:55:26 · 247 阅读 · 0 评论 -
construct-binary-tree-from-inorder-and-postorder-traversal
长度居然是唯一的确定作用子树的方法,因为左右子树的左点和右点可能不存在,而找根结点又不是那么方便,而长度居然成了唯一靠谱的了。#include <iostream>#include <vector>using namespace std; struct TreeNode { int val; TreeNode *left; TreeNode *right;原创 2016-12-23 20:51:06 · 255 阅读 · 0 评论 -
construct-binary-tree-from-preorder-and-inorder-traversal
学会递归地去解决问题,明白每层自己要做什么,层与层的相关性。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NU原创 2016-12-23 19:02:35 · 480 阅读 · 0 评论 -
前序中序求后序,中序后续求前序
求后续#include <bits/stdc++.h>using namespace std;int const maxn=1100;int a[8][8];int vis[8];vector<string> ans;void f(string ins,string post){ if(ins.size()==0) return ; ...原创 2018-09-14 11:05:27 · 448 阅读 · 0 评论