leetcode897
这道题用C++来写,在本地执行正常,但是使用OJ判断输出结果是空,暂时不清楚原因。代码如下:
class Solution {
public:
vector<int> V;
//中序遍历
void MidTree(TreeNode node)
{
if (&node != NULL)
{
if (node.left != NULL)
{
MidTree(*node.left);
}
V.push_back(node.val);
if (node.right != NULL)
{
MidTree(*node.right);
}
}
}
TreeNode Join(TreeNode* t, int ct)
{
if (ct == V.size() - )
{
TreeNode tt = TreeNode(V[ct]);
return tt;
}
TreeNode d = TreeNode(V[ct + ]);
TreeNode* dd = &d;
TreeNode n = Join(dd, ct + );
t->right = &n;
return *t;
}
TreeNode* increasingBST(TreeNode* root) {
MidTree(*root);
TreeNode T = TreeNode(V[]);
TreeNode* TT = &T;
TreeNode x = Join(TT, );
return &x;
}
};
保留原有逻辑,修改为C#代码,则通过所有测试,代码如下:
public class Solution
{
public List<int> V = new List<int>();
//中序遍历
public void MidTree(TreeNode node)
{
if (node != null)
{
if (node.left != null)
{
MidTree(node.left);
}
V.Add(node.val);
if (node.right != null)
{
MidTree(node.right);
}
}
} public TreeNode Join(TreeNode t, int ct)
{
if (ct == V.Count() - )
{
TreeNode tt =new TreeNode(V[ct]);
return tt;
}
TreeNode d = new TreeNode(V[ct + ]);
TreeNode n = Join(d, ct + );
t.right = n;
return t;
}
public TreeNode IncreasingBST(TreeNode root)
{
MidTree(root);
TreeNode T =new TreeNode(V[]);
TreeNode x = Join(T, );
return x;
}
}
不知是leetcode的判断机制问题,还是我的C++写法的问题。之后还是尽量使用C#吧。
leetcode897的更多相关文章
- [Swift]LeetCode897. 递增顺序查找树 | Increasing Order Search Tree
Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root o ...
- LeetCode897. 递增顺序查找树
题目 法一.自己 1 class Solution { 2 public: 3 vector<int>res; 4 TreeNode* increasingBST(TreeNode* ro ...
- LeetCode 897. 递增顺序查找树(Increasing Order Search Tree)
897. 递增顺序查找树 897. Increasing Order Search Tree 题目描述 给定一个树,按中序遍历重新排列树,使树中最左边的结点现在是树的根,并且每个结点没有左子结点,只有 ...
随机推荐
- 013对象—— __clone __toString __call
<?php /** * */ //__clone()方法对一个对象实例进行的浅复制,对象内的基本数值类型进行的是传值复制 /*class a { public $uname; public $n ...
- 日志分析命令awk基础用法
awk awk是一个很好用的文本处理工具,相对于sed常用用作一整行的处理,awk则比较擅长将一行分成数个字段来处理.而在我们性能测试中,可以awk可以帮助我们造数,也可以帮助我们分析日志. 简单来说 ...
- LeetCode OJ:Valid Parentheses(有效括号)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- 2017.10.30 Epicor -ERP
1 公司新用ERP系统,做使用培训,mark... This course reviews the project management flow in the Epicor application. ...
- File I/O的总结
1读写字符文件 BufferedReader br=new BufferedReader(new FileReader("文件路径")); BufferedWriter bw=ne ...
- Amazon 发送个人文档无回复
Amazon 个人文档问题 注意注意 详情见:[使用您的[发送至Kindle]电子邮箱] 重点提示 在电子邮件主题中输入"Convert"以将您的文档转换为Kindle格式,然后再 ...
- (四)java基本语法
关键字 被java赋予了特殊意义的单词: class,new,private,protected,public,static,final,abstract,interface,this,super,I ...
- VC++6.0/MFC中如何限制Edit控件输入 例子,只能输入0和1
1.Insert -> New Class -> 在Base Class中选择CEdit,在Name中输入CMyEdit. 2.在左边的ClassView中,右键击CMyEdit,选择Ad ...
- Linux下Apache配置局域网访问出现的问题
在网站安装好之后,本机可以访问,但是局域网内无法访问,我查看了 /etc/httpd/conf/httpd.conf 看到我的配置如下 <Directory ......> Allow A ...
- 剑指offer-第五章优化时间和空间效率(把数组排列成最小的数)
题目:输入一个正整数数组,将所有的数,排列起来,组成一个最小的数.