[Swift]LeetCode1145. 二叉树着色游戏 | Binary Tree Coloring G
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ Two players play a turn based game on a binary tree.? We are given?the? Initially,the first player names a value? Then,the players take turns starting with the first player.? In each turn,that player chooses a node of their color (red if player 1,blue if player 2) and colors an?uncolored?neighbor of the chosen node (either the left child,right child,or parent of the chosen node.) If (and only if)?a player cannot choose such a node in this way,they must pass their turn.? If both players pass their turn,the game ends,and the winner is the player that colored more nodes. You are the second player.? If it is possible to choose such a? Example 1: Input: root = [1,2,3,4,5,6,7,8,9,10,11],n = 11,x = 3 Output: True Explanation: The second player can choose the node with value 2. Constraints:
有两位极客玩家参与了一场「二叉树着色」的游戏。游戏中,给出二叉树的根节点? ? 游戏从「一号」玩家开始(「一号」玩家为红色,「二号」玩家为蓝色),最开始时, 「一号」玩家从? 「二号」玩家也从? 「一号」玩家给值为? ? 之后两位玩家轮流进行操作,每一回合,玩家选择一个他之前涂好颜色的节点,将所选节点一个?未着色?的邻节点(即左右子节点、或父节点)进行染色。 如果当前玩家无法找到这样的节点来染色时,他的回合就会被跳过。 若两个玩家都没有可以染色的节点时,游戏结束。着色节点最多的那位玩家获得胜利 ??。? 现在,假设你是「二号」玩家,根据所给出的输入,假如存在一个? ? 示例: 输入:root = [1,x = 3 输出:True 解释:第二个玩家可以选择值为 2 的节点。? 提示:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ruby – 如何在命令行上将实例变量传递给HAML模板?
- 利用Flex 4.5 SDK和Flash Builder 4.5开发的web和移动参考应
- ruby-on-rails – 通过rails中的多个条件查找
- objective-c – 如何在Xcode中查找未使用的ivars
- Flex开发小结
- c# – 实现泛型方法处理不同整数类型集合的正确方法是什么?
- c – 如何从std :: optional中获取QByteArray并离开std ::
- Oracle 12c 在生产库停止Data Guard怎么搞?
- ruby-on-rails – Rails:属性的命名约定
- 无法使用参数列表在Swift 2中调用“sendAsynchronousReques