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. 题解 P1403 【[AHOI2005]约数研究】

    题目 看到题解区很多人直接给出结论:答案为 \(\displaystyle \sum_{i=1}^n\lfloor{n\over i}\rfloor\) ,没给出证明,这里给出证明 [分析] 首先,我 ...

  2. addlayer添加神经网络层

    def addlayer(inputs,insize,outsize,activity_function = None):    weights = tf.Variable(tf.random_nor ...

  3. Python—数据结构——链表

    数据结构——链表 一.简介 链表是一种物理存储上非连续,数据元素的逻辑顺序通过链表中的指针链接次序,实现的一种线性存储结构.由一系列节点组成的元素集合.每个节点包含两部分,数据域item和指向下一个节 ...

  4. gitee上传下载代码命令

    在想要下载的文件夹下,鼠标右键,git bash 1.输入git init 进行初始化 2.git remote add origin https://gitee.com/XXXXXXXXXXXXXX ...

  5. 客户主题分析(tableau)—客户分群

    主要分析方面:客户合理分群 客户分群实现:使用聚类构建指标,需理解聚类的分析逻辑,需使用软件:tableau 聚类方法:选择3指标分别为购买总金额,客户购买次数.类平均购买价格(四类的平均购买价格,四 ...

  6. inotifywait命令详解及安装

    https://www.cnblogs.com/pyrene/p/6414724.html     安装 https://www.cnblogs.com/martinzhang/p/4126907.h ...

  7. 32. docker swarm 集群服务通信 之 RoutingMesh - internal 网络

    1. 两个 service 是如何通信的 通过内置的 DNS 服务发现的功能  相互通信的 2. 创建一个 overlay 的 网络 docker network create -d overlay ...

  8. mysql增删查改

    <?php     $db_host   = 'localhost:3306';     $db_user   = 'root';     $db_passwd = '';     $db_na ...

  9. Android studio2.2 app:transformNative_libsWithStripDebugSymbolForDebug

    开始搜到的问题相关链接: http://blog.csdn.NET/doumingliangdendsc/article/details/52595317 https://www.oschina.ne ...

  10. iOS中copy和=的区别

    copy是浅拷贝即指针拷贝,让对象的引用计数加一 在MRC环境下,=只是简单的指针指向,引用对象的引用计数并不会增加,在用局部变量赋值时很容易出现野指针 在ARC环境下,=的效果等同于copy和ret ...