Ubuntu下禁用笔记本自带键盘
All rights reserved by DianeSoHungry (Qingyun Hu).
Original URL: https://www.cnblogs.com/DianeSoHungry/p/8891148.html
Contents
- Construct a binary tree from DLR and LDR traversals.
Problem 1
Construct a binary tree from DLR and LDR traversals.
(根据先序遍历和中序遍历序列,建二叉树)
Example:
Input:
8
1 2 4 7 3 5 6 8
4 7 2 1 5 3 8 6
Output:
Head pointer of the built binary tree
Intuition
For each DLR, you know the first element correspond to the root node. By finding the first element of DLR in LDR, you can split out the subarray of DLR and LDR for left subtree, so as to the subarray of DLR and LDR for right subtree. That is, time for recursion.
Solution in CPP
#include<iostream>
#include<queue>
struct BtNode{
int val;
BtNode* left;
BtNode* right;
BtNode(int val): val(val), left(nullptr), right(nullptr){
};
};
BtNode* BuildBT(int pre[], int mid[], int len){
if (len == 0) {
return nullptr;
}
BtNode* root;
for (int i = 0; i < len; ++i) {
if ( mid[i] == pre[0]) {
root = new BtNode(mid[i]);
root->left = BuildBT(pre+1, mid, i);
root->right = BuildBT(pre+i+1, mid+i+1, len-i-1);
break;
}
}
return root;
}
void TraverseLevelwise(BtNode* bt){
std::queue<BtNode*> q;
q.push(bt);
while (!q.empty()) {
if (q.front() != nullptr) {
std::cout << (q.front()->val) << " ";
q.push(q.front()->left);
q.push(q.front()->right);
}
else {
// std::cout << "null ";
}
q.pop();
}
std::cout << std::endl;
}
int main(){
int n;
std::cin >> n;
int preorder[n];
int midorder[n];
for (int i = 0; i < n; ++i) {
std::cin >> preorder[i];
}
for (int i = 0; i < n; ++i) {
std::cin >> midorder[i];
}
BtNode* res = BuildBT(preorder, midorder, n);
TraverseLevelwise(res);
return 0;
}
After getting the binary tree, for checking, the level order of the tree is printed as below.
1 2 3 4 5 6 7 8
Reference
《剑指offer》
Ubuntu下禁用笔记本自带键盘的更多相关文章
- ubuntu禁用笔记本自带键盘
ubuntu如何禁用笔记本键盘 打开终端运行命令 xinput list Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core ...
- deepin禁用笔记本自带键盘
参考命令: sudo apt install xinput xinput xinput list-props 'AT Translated Set 2 keyboard' xinput set-pro ...
- Linux下禁用笔记本触摸板
1 概述 在Linux下禁用触摸板的方法有很多,这里列举三种: 图形界面配置关闭 modprobe关闭 xinput关闭 2 图形界面配置关闭 笔者的环境为Manjaro+Xfce,其他的桌面也应该类 ...
- 在ubuntu下关闭笔记本触摸板
http://www.cnblogs.com/icejoywoo/archive/2011/04/14/2016318.html 原文地址:http://forum.ubuntu.org.cn/vie ...
- ubuntu下禁用和恢复触摸板
1.一般禁用选项在 settings > mouse and touchpad 中.(16.04通过实验)如果无法禁用或者希望恢复,向下看. 2.命令行键入: xinput ,插卡touchpa ...
- centos系统下禁用笔记本触控板
最近把零几年的老爷笔记本拿出来用,使用windows系统实在太卡了,于是折腾安装上Centos系统了,但是在使用的过程中发现鼠标经常失效.使用了多种方法(比如:http://blog.csdn.net ...
- linux 关闭笔记本自带键盘
linux 命令行工具 xinput list 找到 AT Translated Set 2 keyboard,其 id为 13 设置值为 0 xinput 如果想恢复,对应的值设为1即可 xinpu ...
- Ubuntu下如何禁用IPv6
Ubuntu下如何禁用IPv6 2013-10-16 11:32:02 分类: HADOOP 分布式下的hadoop/hbase运行总出问题,zookeeper连接总是出问题,怀疑可能是ip ...
- 一个禁用mac内置键盘的方法
一个禁用mac内置键盘的方法 强大的 karabiner, 非常好用. 可以直接在有外接键盘连接的情况下, 禁用掉内置键盘 另外一个方法是启用mac的 鼠标键, 感觉用处不是很大, 修饰健并没有被禁用 ...
随机推荐
- glocktop
glocktop: Display or print active GFS2 locks. Index of glocktop man page Read glocktop man page on L ...
- MySQL 中while loop repeat 的基本用法
-- MySQL中的三中循环 while . loop .repeat 求 1-n 的和 -- 第一种 while 循环 -- 求 1-n 的和 /* while循环语法: while 条件 DO 循 ...
- JS中的var、let、const
1.var 在全局window中申明则为全局变量,是全局对象 window 的属性. var sum = 0 console.log(window.sum) console.log(sum); 在函数 ...
- 瓣呀,一个基于豆瓣api仿网易云音乐的开源项目
整体采用material design 风格,本人是网易云音乐的粉丝,所以界面模仿了网页云音乐,另外,项目中尽量使用了5.0之后的新控件. 项目整体采用mvp+rxjava+retrofit 框架,使 ...
- SpringBoot学习7:springboot整合jsp
springboot内部对jsp的支持并不是特别理想,而springboot推荐的视图是Thymeleaf,对于java开发人员来说还是大多数人员喜欢使用jsp 1.创建maven项目,添加pom依赖 ...
- map集合修改其中元素 去除Map集合中所有具有相同值的元素 Properties长久保存的流操作 两种用map记录单词或字母个数的方法
package com.swift.lianxi; import java.util.HashMap; import java.util.Iterator; import java.util.Map; ...
- [优化]Steamroller-freecodecamp算法题目
晚上在medium看到一篇关于找工作的文章,里面提到一个面试题目--flattening an array(扁平化数组).这我好像在哪看过!应该是freecodecamp里的算法某一题.翻了下博客记录 ...
- 关于discuz 不能全文搜索的问题
这个问题客服反馈很多次了,以为discuz 默认搜索只能搜标题,除非配置了sphinx全文搜索引擎. 但是之前比较老的员工说以前能用的,也就是discuz老版本. 今天突然想到是不是discuz纵横搜 ...
- sql常用函数instr()和substr()
Decode decode(条件,值1,翻译值1,值2,翻译值2,...,缺省值) 该函数与程序中的 If...else if...else 意义一样 NVL 格式:NVL( string1, rep ...
- 【jQuery】手机验证码倒计时效果
<ul class="ulist"> <li class="group"> <label class="label&qu ...