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

Example:

Input: s = "++++"
Output:
[
"--++",
"+--+",
"++--"
]
class Solution {
public List<String> generatePossibleNextMoves(String s) {
List<String> res = new ArrayList<>();
for (int i = 0; i < s.length() - 1; i++) {
if (s.charAt(i) == '+' && s.charAt(i + 1) == '+') {
res.add(s.substring(0, i) + "--" + s.substring(i + 2));
}
}
return res;
}
}

[LC] 293. Flip Game的更多相关文章

  1. 293. Flip Game只翻转一步的加减号翻转游戏

    [抄题]: You are playing the following Flip Game with your friend: Given a string that contains only th ...

  2. 293. Flip Game

    题目: You are playing the following Flip Game with your friend: Given a string that contains only thes ...

  3. LeetCode 293. Flip Game

    原题链接在这里:https://leetcode.com/problems/flip-game/description/ 题目: You are playing the following Flip ...

  4. [LeetCode] 293. Flip Game 翻转游戏

    You are playing the following Flip Game with your friend: Given a string that contains only these tw ...

  5. leetcode 293.Flip Game(lintcode 914) 、294.Flip Game II(lintcode 913)

    914. Flip Game https://www.cnblogs.com/grandyang/p/5224896.html 从前到后遍历,遇到连续两个'+',就将两个加号变成'-'组成新的字符串加 ...

  6. LC 971. Flip Binary Tree To Match Preorder Traversal

    Given a binary tree with N nodes, each node has a different value from {1, ..., N}. A node in this b ...

  7. LC 926. Flip String to Monotone Increasing

    A string of '0's and '1's is monotone increasing if it consists of some number of '0's (possibly 0), ...

  8. 【LeetCode】293. Flip Game 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcode ...

  9. <String> 186 293 294 249

    186. Reverse Words in a String II 先反转整个字符串,再反转每个单词(调整顺序也可以) 反转单词的时候:当 j 指到最后一个字符的时候,或者 j 的下一个指向空格,则反 ...

随机推荐

  1. 关于域名转发proxy_pass

    在配置nginx的时候,有一个需求,访问m.XXX.com的时候,需要实际访问www.YYY.com/m,并且域名不能发生变化. 达成这个需求有两种做法: 第一种就是301跳转,使用rewrite来跳 ...

  2. Ubuntu Hadoop使用过程中的一些技巧1

    权限不足:打开有管理员权限的文件夹:sudo nautilus  输入密码即可进入最高权限的文件管理界面可以快速对文件进行修改删除操作 修改权限:chmod命令     chmod -R 777 文件 ...

  3. GBDT入门

    GBDT(MART)迭代决策树入门教程 GBDT(Gradient Boosting Decision Tree) 又叫 MART(Multiple Additive Regression Tree) ...

  4. UVALive 6491 You win! 状态DP

    这个题目上周的对抗赛的,美国2013区域赛的题目,上次比赛真惨,就做出一道题,最多的也只做出两道,当时想把这题做出来,一直TLE. 这个题目用挂在Hunnu OJ的数据可以过,但UVALive上死活过 ...

  5. cmd 进入指定文件夹

    1.通常情况下,我们要进入其他盘符下的任意目录,需要在CMD窗口运行两次命令:第一次,进入盘符,第二次进入指定目录 #进入D盘 d: #进入D盘下的anaconda目录 cd anacond 2.通过 ...

  6. 吴裕雄--天生自然MySQL学习笔记:MySQL LIKE 子句

    在 MySQL 中使用 SQL SELECT 命令来读取数据, 同时我们可以在 SELECT 语句中使用 WHERE 子句来获取指定的记录. WHERE 子句中可以使用等号 = 来设定获取数据的条件, ...

  7. 1. react 基础 简介 及 环境搭建

    一.简介 由 Facebook 推出 2013 年 开源 的 函数式编程的 使用人数最多的 前端框架 拥有健全的文档与完善的社区 ( 官网 ) react 16 称为 React Fiber ( 底层 ...

  8. 用Chrome网页获取PDF?

    在网页浏览的时候,我常常想保存网页上的内容 这时候有几种选择,要么copy and paste,要么windows自带截图,要么就是借用tencent的截图工具... 但是对于一些用chrome预览的 ...

  9. 瑞芯微RK3399六核-迅为3399开发板介绍

    迅为3399开发板基于瑞芯微的RK3399处理器设计,Rockchip RK3399是瑞芯微推出的一款低功耗.高性能的应用处理器芯片,该芯片基于Big.Little架构,即具有独立的NEON协同处理器 ...

  10. sublime3激活方法

    激活方法参考这里 $ tail -n4 /etc/hosts # https://blog.csdn.net/DeMeng33/article/details/80536926 127.0.0.1 w ...