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. mybatis中foreach collection的三种用法

    foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有 item,index,collection,open,separator,close. ...

  2. OC中浮点数转整数的进一法和去尾法

    //去尾法,最小去尾单位为0.000001 floorf(4.1)4 floorf(4.9)4 floorf(4.999999)4 floorf(4.9999999)5 //进一法,最小进位单位为0. ...

  3. Cpp:"->"和"."的区别

    environments:gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project) class data{ publi ...

  4. 苹果智能AR挡风玻璃靠谱吗?

    在过去十年,外界给苹果的形象一直是"伟大的硬件公司",他们的产品在外观方面往往比内涵更加引人注目,兼具娱乐性和艺术性, iPhone/iPad/iPod莫不如此,所以,当坊间传闻苹 ...

  5. SeetaFaceEngine系列3:Face Identification编译和使用

    前面两篇介绍了怎样编译SeetaFace的前两部分,现在就来讲下第三部分Face Identification的编译和使用. 其实,步骤基本上是一直的,如下: 1.新建一个空的DLL工程: 2.修改配 ...

  6. CodeForces 1292A NEKO's Maze Game(思维)

    #include <stdio.h> #include <string.h> #include <iostream> #include <string> ...

  7. java客房管理小项目,适合java小白练手的项目!

    java客房管理小项目 这个客房管理小项目,适合java初学者练手.功能虽然不多,但是内容很齐全! 喜欢这样文章的可以关注我,我会持续更新,你们的关注是我更新的动力!需要更多java学习资料的也可以私 ...

  8. SpringBoot2中,怎么生成静态文档

    SpringBoot2中,怎么生成静态文档 在实际开发过程中,我们通过swagger就可以生成我们的接口文档,这个文档就可以提供给前端人员开发使用的.但是,有时候,我们需要把我们的接口文档,提供给第三 ...

  9. cassandra 系统分析 架构

    cassandra cassandra是无中心节点的列式数据库 集群管理:      使用gossip算法,最终每个节点都知道集群中的所有节点信息,新增一个节点,新节点发送上线消息,     其他节点 ...

  10. MySQL笔记(二)——查询数据

    数据库管理系统的一个最重要的功能就是数据查询,数据查询不应只是简单的查询数据库中存储的数据,还应该是根据需要对数据进行筛选,以及确定数据以什么样的格式显示.本篇笔记主要介绍单表查询,子查询,连接查询. ...