Flip Game II -- LeetCode
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.
思路:递归求解。
class Solution {
public:
bool canWin(string s) {
for (int i = ; i < s.size(); i++)
if (s[i] == '+' && s[i-] == '+') {
s[i] = s[i-] = '-';
if (!canWin(s)) return true;
s[i] = s[i-] = '+';
}
return false;
}
};
Flip Game II -- LeetCode的更多相关文章
- leetcode 293.Flip Game(lintcode 914) 、294.Flip Game II(lintcode 913)
914. Flip Game https://www.cnblogs.com/grandyang/p/5224896.html 从前到后遍历,遇到连续两个'+',就将两个加号变成'-'组成新的字符串加 ...
- Path Sum II - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Path Sum II - LeetCode 注意点 不要访问空结点 解法 解法一:递归,DFS.每当DFS搜索到新节点时,都要保存该节点.而且每当找出一 ...
- Subsets II - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Subsets II - LeetCode 注意点 有重复的数字 数组可能是无序的,要先排序 解法 解法一:递归,只需要在Subsets中递归写法的基础上 ...
- Permutations II - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Permutations II - LeetCode 注意点 不确定有几种排列 解法 解法一:因为有重复的数字所以排列的个数不确定几个,一直生成新的排列直 ...
- [LeetCode] Flip Game II 翻转游戏之二
You are playing the following Flip Game with your friend: Given a string that contains only these tw ...
- LeetCode Flip Game II
原题链接在这里:https://leetcode.com/problems/flip-game-ii/ 题目: You are playing the following Flip Game with ...
- [LeetCode] 294. Flip Game II 翻转游戏 II
You are playing the following Flip Game with your friend: Given a string that contains only these tw ...
- LeetCode 294. Flip Game II
原题链接在这里:https://leetcode.com/problems/flip-game-ii/ 题目: You are playing the following Flip Game with ...
- 【LeetCode】294. Flip Game II 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 记忆化搜索 日期 题目地址:https://leetc ...
随机推荐
- linux pthread【转】
转自:http://www.cnblogs.com/alanhu/articles/4748943.html Posix线程编程指南(1) 内容: 一. 线程创建 二.线程取消 关于作者 线程创 ...
- Sql Server 2014/2012/2008/2005 数据库还原出现 3154错误的解决办法
在Sql Server 数据库还原出现 3154错误 解决方法1:不要在数据库名字上点右键选择还原,而要是在根目录“数据库”三个字上点右键选择还原,然后再选择数据库,问题便可以解决,如果不行参照方法 ...
- Oracle 内存管理
--内存分配建库时可以先分配系统内存的50%-80%给Oracle,后期根据业务再进行调整.SGA.PGA分配比例:OLTP:SGA %80 , PGA %20OLAP:SGA %50 , PGA % ...
- 【bzoj3545】peaks
离线一下,动态开点+线段树合并,然后权值线段树上询问kth即可. #include<bits/stdc++.h> ; *; using namespace std; ; inline in ...
- 去掉a标签的虚线框,避免出现奇怪的选中区域
a{blr:expression(this.onFocus=this.blur())}/*去掉a标签的虚线框,避免出现奇怪的选中区域*/
- IE中部分版本的浏览器对Select标签设置innerHTML无效的问题
这样写的代码:document.getElementById('data_list').innerHTML = data;//data是ajax返回的数据 结果发现在ie10的兼容模式下面下拉框没有内 ...
- jdbc简单小登陆demo
package com.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultS ...
- 【python】资料记录
今天看了一些关于python的知识: 1.装饰器:https://www.zhihu.com/question/25950466/answer/31731502 2.*args的用法:http://b ...
- [PAT] 1141 PAT Ranking of Institutions(25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- win10网速慢
升级到win10之后发现网速特别慢,搜了下,网上的解决办法果然好使,按照如下操作即可. 返回桌面,按WIN+R键组合,运行gpedit.msc 打开组策略 依次展开管理模板->网络->Qo ...