博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Swift]LeetCode293. 翻转游戏 $ Flip Game
阅读量:4577 次
发布时间:2019-06-08

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

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝()
➤GitHub地址:
➤原文地址: 
➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

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 twoconsecutive "++" 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 compute all possible states of the string after one valid move.

For example, given s = "++++", after one move, it may become one of the following states:

[ "--++",  "+--+",  "++--"] 

If there is no valid move, return an empty list [].


您正在和您的朋友玩以下翻转游戏:给定一个仅包含这两个字符的字符串:+和-,您和您的朋友轮流将两个插入“++”翻转为“--”。游戏结束时,一个人不能再做一个动作,因此另一个人将是赢家。

写一个函数来计算一次有效移动后字符串的所有可能状态。

例如,给定s=“+++++”,移动一次后,它可能成为以下状态之一:

[ "--++",  "+--+",  "++--"] 

如果没有有效的移动,请返回空列表[]。


 

Solution:

1 class Solution { 2     func generatePossibleNextMoves(_ s:String) ->[String] { 3         var res:[String] = [String]() 4         var arrS:[Character] = Array(s) 5         for i in 1..
String {21 let theIndex = self.index(self.endIndex, offsetBy: index - self.count)22 return String(self[theIndex..
String {29 let start = self.index(self.startIndex, offsetBy: max(0, begin))30 let end = self.index(self.startIndex, offsetBy: min(self.count, begin + count))31 return String(self[start..

 

转载于:https://www.cnblogs.com/strengthen/p/10692426.html

你可能感兴趣的文章
日期时间处理函数收集
查看>>
HDOJ树形DP专题之Anniversary party
查看>>
linux日常管理-系统服务
查看>>
Enter Query Mode Search Tricks Using Enter_Query Built-in in Oracle Forms
查看>>
Form属性、内置子程序、触发器、系统变量
查看>>
广州夜景一
查看>>
linux编译安装python3和安装django
查看>>
PHP数组对象互转
查看>>
JVM(2)--一文读懂垃圾回收
查看>>
iOS ERROR: unable to get the receiver data from the DB 解决方式
查看>>
游戏开发——战斗系统设计技巧
查看>>
Android ROM 制作教程
查看>>
Android模拟器使用SD卡
查看>>
新手Oracle安装及使用入门
查看>>
帝国cms灵动标签下常用标签
查看>>
STL学习笔记(关联式容器)
查看>>
Android生成xml
查看>>
python入到到实战--第十章----文件
查看>>
FMDataBase 打开sqlite的外键约束功能
查看>>
Nmap 7.70新增功能——扫描主机所有IP
查看>>