294. Flip Game II
来源:互联网 发布:书生商友软件 编辑:程序博客网 时间:2024/06/07 08:08
You are playing the following Flip Game with your friend: Given a string that contains only these two characters: +
and -
, you and your friend take turns to flip two consecutive "++"
into "--"
. The game ends when a person can no longer make a move and therefore the other person will be the winner.
Write a function to determine if the starting player can guarantee a win.
For example, given s = "++++"
, return true. The starting player can guarantee a win by flipping the middle "++"
to become "+--+"
.
Follow up:
Derive your algorithm's runtime complexity.
public class Solution { public boolean canWin(String s) { return helper(s.toCharArray()); } private boolean helper(char[] chs) { for (int i = 0; i < chs.length - 1; i ++) { if (chs[i] == '+' && chs[i + 1] == '+') { chs[i] = '-'; chs[i + 1] = '-'; boolean win = !helper(chs); chs[i] = '+'; chs[i + 1] = '+'; if (win) { return true; } } } return false; }}
0 0
- 294. Flip Game II
- LeetCode 294. Flip Game II
- Leetcode 293. Flip Game & 294. Flip Game II
- [leetcode] 294. Flip Game II 解题报告
- [Leetcode] 294. Flip Game II 解题报告
- *LeetCode-Flip Game II
- [LeetCode294] Flip Game II
- [LeetCode294]Flip Game II
- [leetcode294]Flip Game II
- [LeetCode294] Flip Game II
- Flip Game II
- Flip Game II
- LeetCode 294. Flip Game II(反转游戏II)
- Leetcode 294. Flip Game II (回溯,记忆化)
- LeetCode 题解(277) :Flip Game II
- Flip Game
- Flip Game
- Flip Game
- HDU 3065 病毒侵袭持续中 (AC自动机)
- Truck History
- Myeclipse错误:Errors occurred during the build. Errors running builder 'DeploymentBuilder' on project
- HDOJ-魔咒词典
- 三层架构
- 294. Flip Game II
- Go操作XML
- 图像处理之_导数微分
- 自定义View:侧滑菜单动画实现
- 图像处理之_霍夫(Hough)变换
- [leetCode刷题笔记]300. Longest Increasing Subsequence
- VNC安装与配置
- Leetcode 424. Longest Repeating Character Replacement
- C++primer学习笔记-----4.11类型转换