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 ...
随机推荐
- SSL Certificate Signed Using Weak Hashing Algorithm 和SSL Medium Strength Cipher Suites Supported的解决方案
这两天有个项目被扫描器报了几个中危,都是SSL证书的问题.记录一下解决方案吧. 第一个问题:SSL Certificate Signed Using Weak Hashing Algorithm 这里 ...
- api接口的记录
http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.billboard.billList&type=1& ...
- Docker构建FastDFS镜像
https://blog.csdn.net/qq_26440803/article/details/83066132 Dockerfile 所需依赖: fastdfs libfastcommon ...
- Beginning Math and Physics For Game Programmers (Wendy Stahler 著)
Chapter 1. Points and Lines (已看) Chapter 2. Geometry Snippets (已看) Chapter 3. Trigonometry Snippets ...
- KiCad EDA 原理图库的最佳实践
KiCad EDA 原理图库的最佳实践 由于有 Alias 别名元件,可以不用一个每一个元件都有一个元件. 对每种元件类型建议一个元件库. 因为 Value 和 元件名是一样的,所以元件名要尽可能的简 ...
- 解决openstack实例主机名后缀问题
参考地址https://ask.openstack.org/en/question/26918/change-novalocal-suffix-in-hostname/ 问题现象 可以看到主机名的后缀 ...
- 20165308『网络对抗技术』Exp5 MSF基础应用
20165308『网络对抗技术』Exp5 MSF基础应用 一.原理与实践说明 实践内容 本实践目标是掌握metasploit的基本应用方式,重点常用的三种攻击方式的思路.具体需要完成: 一个主动攻击实 ...
- dd/MMM/yyyy:hh:mm:ss +0800日期格式的转化
private static void myHandler() throws ParseException { String dtime1 = "23/Apr/2019:04:08:00 + ...
- Teamviewer远程控制
设置无人值守的固定密码,不使用随机码进行远程控制访问 设置好密码之后,以后只要通过Teamviewer生成的固定ID,再加上你设置的密码就可以随时进行远程访问了,而不需要使用生成的随机码.
- 信号监测---verilog
信号监测---verilog 此模块用于监测某一信号源是否持续稳定的传送. 监测思路:监测信号源高电平或者低电平的宽度是否始终保持一致(一定范围内允许有误差) `timescale 1ns / 1ps ...