leetcode971
class Solution:
def flipMatchVoyage(self, root, voyage):
res = []
self.i = 0
def dfs(root):
if not root: return True
if root.val != voyage[self.i]: return False
self.i += 1
if root.left and root.left.val != voyage[self.i]:
res.append(root.val)
root.left,root.right = root.right, root.left
return dfs(root.left) and dfs(root.right)
return res if dfs(root) else [-1]
leetcode971的更多相关文章
- [Swift]LeetCode971.翻转二叉树以匹配先序遍历 | Flip Binary Tree To Match Preorder Traversal
Given a binary tree with N nodes, each node has a different value from {1, ..., N}. A node in this b ...
随机推荐
- VS2017 C/C++输入密码显示*星号
VS2017 C/C++输入密码显示*星号 _getch()函数使用时遇到的坑 参考: https://blog.csdn.net/guin_guo/article/details/46237905 ...
- Tenka 1 Computer Contest C-Align
C - Align Time limit : 2sec / Memory limit : 1024MB Score : 400 points Problem Statement You are giv ...
- [双硬盘GPT分区安装linux] ----安装
最近机器学习课程需要用到pytorch, 基于cuda8的pytorch的需要,最终决定还是要安装一个linux系统在我的windows10机器上.本篇记录安装过程备用. 本人笔记本是联想Y520,系 ...
- Spring.factories扩展机制
和Java SPI的扩展机制类似,Spring Boot采用了spring.factories的扩展机制,在很多spring的starter 包中都可以找到,通过在 META-INF/spring.f ...
- HttpSimpleClient连接服务器
public class HttpSimpleClient { /** * 发送GET请求. */ static public HttpResult httpGet(String url, List& ...
- 斐讯N1折腾记
斐讯N1折腾记:运行 Linux 及优化 2018-06-23 37条评论 4,445次阅读 11人点赞 最后更新时间:2019年03月10日 咳咳咳,上篇教程教大家给斐讯 N1 降级并且刷了 ...
- DSP 运行时间计算函数--_itoll(TSCH,TSCL);
DSP OMAP 程序耗时测定 CPU周期 两种方法 利用TSCL和TSCH来计算时钟周期,这两天看了一下如何他们 DSP开发,测量某个函数或某段代码的cycles消耗是经常要做的 事情,常用的pro ...
- 跨域1-CORS跨域
1.跨域:请求的资源和当前网站的,协议/域名/端口 不一样,会发起跨域HTTP请求 2.为什么会跨域出于安全原因,浏览器限制从脚本内发起的跨源HTTP请求. 例如,XMLHttpRequest和Fet ...
- 《重构-改善既有代码的设计》学习笔记---Replace Temp with Query(以查询取代临时变量)
临时变量的问题在于: 它们是暂时的,而且只能在所属函数内使用.由于临时变量只在所属函数内可见,所以,如果很多地方都在用这个临时变量,就会驱使你写出更长的函数.如果把临时变量替换为一个查询,那么其他函数 ...
- ABBYY FineReader 14OCR解锁
ABBYY FineReader 14是2017年新推的文字处理编辑软件,能够将图像扫描转换成文档处理.不论是在使用群体方面还是功能特性方面都是极好的. •确保扫描仪正确地连接到电脑,并将其打开.查阅 ...