leetcode144
/**
* Definition for a binary tree node.
* public class TreeNode {
* public int val;
* public TreeNode left;
* public TreeNode right;
* public TreeNode(int x) { val = x; }
* }
*/
public class Solution {
Stack<int> S = new Stack<int>(); private void preNode(TreeNode node)
{
if (node != null)
{
S.Push(node.val);
if (node.left != null)
{
preNode(node.left);
}
if (node.right != null)
{
preNode(node.right);
}
}
} public IList<int> PreorderTraversal(TreeNode root)
{
preNode(root);
var list = S.Reverse().ToList();
return list;
}
}
https://leetcode.com/problems/binary-tree-preorder-traversal/#/description
leetcode144的更多相关文章
- LeetCode144:Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary t ...
- [Swift]LeetCode144. 二叉树的前序遍历 | Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. Example: Input: [1,null,2,3 ...
- LeetCode144:Binary Tree Preorder Traversal
题目: Given a binary tree, return the preorder traversal of its nodes' values. For example: Given bina ...
- Leet-code144. Binary Tree Preorder Traversal
这是一道将二叉树先序遍历,题目不难. 首先采用深搜递归 /** * Definition for a binary tree node. * public class TreeNode { * int ...
- Leetcode144. Binary Tree Preorder Traversal二叉树的前序遍历
给定一个二叉树,返回它的 前序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,2,3] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 递归: class S ...
- leetcode144 longest-palindromic-substring
题目描述 找出给出的字符串S中最长的回文子串.假设S的最大长度为1000,并且只存在唯一解. Given a string S, find the longest palindromic substr ...
- LeetCode144 二叉树的前序遍历
给定一个二叉树,返回它的 前序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,2,3] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? /** * Defin ...
- LeetCode二叉树的前序、中序、后序遍历(递归实现)
本文用递归算法实现二叉树的前序.中序和后序遍历,提供Java版的基本模板,在模板上稍作修改,即可解决LeetCode144. Binary Tree Preorder Traversal(二叉树前序遍 ...
- LeetCode 144. 二叉树的前序遍历(Binary Tree Preorder Traversal)
144. 二叉树的前序遍历 144. Binary Tree Preorder Traversal 题目描述 给定一个二叉树,返回它的 前序 遍历. LeetCode144. Binary Tree ...
随机推荐
- Qt中QT_BEGIN_NAMESPACE和QT_END_NAMESPACE的作用
在Qt中,我们经常会看到 QT_BEGIN_NAMESPACE class QAction; class QMenu; class QPlainTextEdit; QT_END_NAMESPACE 这 ...
- vc++6 Platform SDK February 2003
vc++6.0 sp6 ftp://ejiasoft:softejia@ejia2.tust.edu.cn/else/VC++.6.0.with.SP6.ISO MSDN http://ftp.sds ...
- 使用Kali Linux执行中间人攻击(演示)
中间人攻击也叫Man-In-The-Middle-Attack. 我假设你已经知道中间人攻击的基本概念,引用一段wikipedia: 中间人攻击(Man-in-the-middle attack,缩写 ...
- NGINX 配置文件配置url重写
1.项目在根目录: location / { index index.html index.htm index.php l.php; autoindex ...
- 在linux中使用shell来分析统计日志中的信息
在运维工作中,要经常分析后台系统的日志,通过抓取日志中的关键字信息,对抓取结果进行统计,从而为监控结果提供基础数据.下面的shell演示了如何从大量的日志中取得想要的统计结果.其中展示了各种有趣的命令 ...
- java编写创建数据库和表的程序
本文示例可见一斑了,主要是通过Java对SQL语句进行操作,和普通的增删改查的原理是一样的: import java.sql.*; public class Test { public static ...
- Microsoft office2007免费版下载(安装 + 破解)
office2007官方下载 免费完整版是微软推出的办公软件,office2007使用方法很简单,解压软件之后,运行“setup.exe”之后按照提示点击下一步,输入产品秘钥,就可以正常安装了.Mic ...
- 解决Chrome关联HTML文件,图标不显示的问题。
解决Chrome关联HTML文件,图标不显示的问题. 一.方法一 1.win+r,输入regedit,调出注册表信息,按下Ctrl+F,在注册表里搜索.在注册表里新建几个文件就可以了 a.新建Old ...
- win10环境变量的配置
c盘->环境变量: 1.添加变量名和变量值 变量名:JAVA_HOME 变量值:C:\Program Files\Java\jdk1.8.0_161 2.添加变量名和变量值 变量名:JAVA_H ...
- django配置静态文件
django配置静态文件 参考文章链接:http://blog.csdn.net/hireboy/article/details/8806098