博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode-Flip Game II
阅读量:7027 次
发布时间:2019-06-28

本文共 862 字,大约阅读时间需要 2 分钟。

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.

若是有一段"++", 剩下的段和"--"组合 can not win, 那么返回true.

从头到尾试遍了没找到这么一段"++", 返回false.

Time Complexity: exponential.

T(n) = (n-2) * T(n-2) = (n-2) * (n-4) * T(n-4) = O(n!!)

public class Solution {    public boolean canWin(String s) {        for(int i = 1; i

 

转载于:https://www.cnblogs.com/incrediblechangshuo/p/9388359.html

你可能感兴趣的文章
思科路由器限速设置全解
查看>>
IO流(三)_File类_字节流与字符流
查看>>
安全测试常用功能点
查看>>
varnish3.0清除缓存
查看>>
Bitnami-Redmine外网访问phpmyadmin设置
查看>>
iOS使用OpenAL播放PCM流
查看>>
Elm学习指南
查看>>
通读SDWebImage①--总体梳理、下载和缓存
查看>>
929. 独特的电子邮件地址
查看>>
19. Spring Boot Shiro 权限管理
查看>>
【C语言】14-返回指针的函数与指向函数的指针
查看>>
uoj#119. 【UR #8】决战圆锥曲线(线段树+复杂度分析)
查看>>
docker 13 dockerfile的保留字指令
查看>>
(转)开放window是服务器端口——以8080为例
查看>>
C# 通过IEnumberable接口和IEnumerator接口实现泛型和非泛型自定义集合类型foreach功能...
查看>>
微信小程序初识
查看>>
Ubuntu中打开RAR文件
查看>>
数字转换大写人民币的delphi实现
查看>>
开源的asp.net工作流程引擎。 http://ccflow.org
查看>>
日期和时间字符串格式化
查看>>