leetcode589
树的先序遍历,使用递归实现。
class Solution {
public:
vector<Node> Tree;
void preTree(Node node)
{
Tree.push_back(Node(node.val, node.children));
for (auto n : node.children)
{
Node node;
node = Node(n->val, n->children);
preTree(node);
}
}
vector<int> preorder(Node* root) {
vector<int> V;
if (root != NULL)
{
preTree(*root);
for (auto n : Tree)
{
V.push_back(n.val);
}
}
return V;
}
};
leetcode589的更多相关文章
- (N叉树 递归) leetcode589. N-ary Tree Preorder Traversal
Given an n-ary tree, return the preorder traversal of its nodes' values. For example, given a 3-ary ...
- leetcode589. N-ary Tree Preorder Traversal
python 版: class Solution(object): def preorder(self, root): ret, q = [], root and [root] while q: no ...
- Leetcode589.N-ary Tree Preorder TraversalN叉树的前序遍历
给定一个 N 叉树,返回其节点值的前序遍历. class Node { public: int val; vector<Node*> children; Node() {} Node(in ...
- LeetCode589. N叉树的前序遍历
题目 法一.递归 1 class Solution { 2 public: 3 vector<int>ans; 4 void dfs(Node* root){ 5 if(root!=NUL ...
- [树]LeetCode589 N叉树的前序遍历
LeetCode N叉树的前序遍历 前言:树的前中后序遍历已经是很经典的题目的,要么递归要么迭代,不过还是比较习惯于递归的写法 TITLE 给定一个 n 叉树的根节点 root ,返回 其节点值的 前 ...
- (N叉树 递归) leetcode 590. N-ary Tree Postorder Traversal
Given an n-ary tree, return the postorder traversal of its nodes' values. For example, given a 3-ary ...
- LeetCode解题思路
刷完题后,看一下其他人的solution,受益匪浅. 可以按不同的topic刷题,比如数组.字符串.集合.链表等等.先做十道数组的题,接着再做十道链表的题. 刷题,最主要的是,学习思路. 多刷几遍.挑 ...
- LeetCode 589. N叉树的前序遍历(N-ary Tree Preorder Traversal)
589. N叉树的前序遍历 589. N-ary Tree Preorder Traversal LeetCode589. N-ary Tree Preorder Traversal 题目描述 给定一 ...
随机推荐
- JavaWeb -- 邮件收发
smtp协议: telnet smtp.qq.com 25 ehlo kevin auth login eGlhbmdqaWU1NUBxcS5jb20= a2V2aW5feGlhbmc1NQ== ma ...
- JavaWeb -- 内省—beanutils工具包 的使用
Apache组织开发了一套用于操作JavaBean的API,这套API考虑到了很多实际开发中的应用场景,因此在实际开发中很多程序员使用这套API操作JavaBean,以简化程序代码的编写. Beanu ...
- LightOJ 1245 数学
Harmonic Number (II) Description I was trying to solve problem '1234 - Harmonic Number', I wrote the ...
- Android dependency has different version.You should manually set the same version via DependencyReso
有时候导入一些module时,会出现以下问题 Android dependency 'com.android.support:support-v4' has different version for ...
- java导包
下载响应的zip文件,就可以导入了,导入src目录也是可以的.
- mogon操作数据库
返回的本来就是promise redis是内存数据库,更适合放session等一些东西.而mongo不是.
- compile to 32-bit elf file
nasm -f elf -o a.o a.asm gcc -c -m32 -o b.o b.c ld -s -m elf_i386 -Ttext 0x30400 -o b.bin b.o a.o
- Linux-Crontab服务
1.安装并检查Crontab服务 检查cron服务: 检查Crontab工具是否安装:crontab -l 检查crond服务是否启动:service crond status 安装cron: yum ...
- Java 代码复用 —— 泛型
public interface Comparable<T> { public int compareTo(T o); } 1. 接口(Comparable:可比较接口) public s ...
- FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
/******************************************************************************** * FAT-fs (mmcblk0p ...