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 题目描述 给定一个树,按中序遍历重新排列树,使树中最左边的结点现在是树的根,并且每个结点没有左子结点,只有 ...
随机推荐
- sql如何分组选择显示最新的一条数据
怎样在数据库的一个表里筛选出每一人的时间最新的一条记录?用SQL语句 wenchuan408 wenchuan408 结帖率:100% sql数据库 yhh name ...
- 交叉编译工具链介绍《Building Embedded Linux Systems》
1.前言 配置和编译一个合适的GNU工具链是相对复杂的并且需要很精细的操作,包括你需要对不同软件库之间的依赖关系.它们的各自的任务,不同软件库版本情况都有比较好的了解,编译工具链是一个乏味的工作. 2 ...
- 安装nodejs+npm的体验
NODEJS.NPM安装配置步骤(WINDOWS版本) 1.windows下的NodeJS安装是比较方便的(v0.6.0版本之后,支持windows native),只需要登陆官网(http://no ...
- HTML中的颜色简写
1.HTML中颜色的五种写法 1)直接用颜色英文名字表示 例如表示背景颜色为白色: 2.通过16进制数表示 例如表示背景颜色为黑色 3).通过RGB方式表示 RGB:是红色(red)绿色(green) ...
- access_ok | 检查用户空间内存块是否可用
access_ok() 函数是用来代替老版本的 verify_area() 函数的.它的作用也是检查用户空间指针是否可用. 函数原型:access_ok (type, addr, size); 变量说 ...
- [Scala]Scala学习笔记三 Map与Tuple
1. 构造映射 可以使用如下命令构造一个映射: scala> val scores = Map("Alice" -> 90, "Kim" -> ...
- debounce与throttle区别
在2011年,Twitter网站曾爆出一个问题:在主页往下滚动时,页面会变得缓慢以致没有响应.John Resig发表了一篇文章< a blog post about the problem&g ...
- Ubuntu使用PlayOnLinux笔记
playonlinux官网:https://www.playonlinux.com/en/ 帮助文档:https://www.playonlinux.com/en/documentation.html ...
- python学习之基本类型
#我的第一个python程序 print("hello world"); #多行字符串 print("""\ Usage: thingy [OPTIO ...
- jenkins部署应用
1. 系统介绍 Jenkins系统提供了一键部署的作用,整个过程有从提测的分支抓取代码,编译,打包,把打的包部署在应用服务器上,基本有Service,Web和Worker等. 2. Jen ...