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 ...
随机推荐
- 全面了解Nginx主要应用场景(数漫江湖)
前言 本文只针对Nginx在不加载第三方模块的情况能处理哪些事情,由于第三方模块太多所以也介绍不完,当然本文本身也可能介绍的不完整,毕竟只是我个人使用过和了解到过得.所以还请见谅,同时欢迎留言交流 N ...
- HDU 2639 Bone Collector II (dp)
题目链接 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took part in ...
- vue装逼神器简述
主要是分享下用vuejs开发项目过程中遇到的问题,vuejs开发的优势和需要注意的地方. 项目主要页面:主页,最新,分类,分类列表,详情页,结果页,斗图(列表,制作页) 效果图: 地址:https:/ ...
- 初识费用流 模板(spfa+slf优化) 餐巾计划问题
今天学习了最小费用最大流,是网络流算法之一.可以对于一个每条边有一个容量和一个费用(即每单位流的消耗)的图指定一个源点和汇点,求在从源点到汇点的流量最大的前提下的最小费用. 这里讲一种最基础也是最好掌 ...
- Exploring Qualcomm's TrustZone Implementation
转自 http://bits-please.blogspot.com/2015/08 (需要FQ, 狗日的墙) In this blog post, we'll be exploring Qua ...
- win7旗舰版64位缺失tbb.dll文件
win7旗舰版64位缺失tbb.dll文件 https://zhidao.baidu.com/question/688589990330312804.html 到好的电脑中复制一个,黏贴到下同的路径下 ...
- selenium遇到的一些问题,持续更新
1.今天早上运行程序的时候,发现我在循环点击一个元素的时候出现了错误 selenium.common.exceptions.StaleElementReferenceException: Messag ...
- python 基础习题
1.8<<2等于? 8 ---> 1000 32 ---> 100000 -----------结果--- 32 2.通过内置函数计算5除以2的余数 print(dir()) ...
- J2EE MySQL Date数据保持一致解决方案
1.设置MySQL时区,明确指定 MySQL 数据库的时区,不使用引发误解的 CST show variables like '%time_zone%';set global time_zone = ...
- MySQL的七种join
转载 原文地址 建表 在这里我们先建立两张有外键关联的两张表: CREATE DATABASE db0206; USE db0206; CREATE TABLE `db0206`.`tbl_dept` ...