[LC] 293. Flip Game
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的更多相关文章
- 293. Flip Game只翻转一步的加减号翻转游戏
[抄题]: You are playing the following Flip Game with your friend: Given a string that contains only th ...
- 293. Flip Game
题目: You are playing the following Flip Game with your friend: Given a string that contains only thes ...
- LeetCode 293. Flip Game
原题链接在这里:https://leetcode.com/problems/flip-game/description/ 题目: You are playing the following Flip ...
- [LeetCode] 293. Flip Game 翻转游戏
You are playing the following Flip Game with your friend: Given a string that contains only these tw ...
- leetcode 293.Flip Game(lintcode 914) 、294.Flip Game II(lintcode 913)
914. Flip Game https://www.cnblogs.com/grandyang/p/5224896.html 从前到后遍历,遇到连续两个'+',就将两个加号变成'-'组成新的字符串加 ...
- 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 ...
- 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), ...
- 【LeetCode】293. Flip Game 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcode ...
- <String> 186 293 294 249
186. Reverse Words in a String II 先反转整个字符串,再反转每个单词(调整顺序也可以) 反转单词的时候:当 j 指到最后一个字符的时候,或者 j 的下一个指向空格,则反 ...
随机推荐
- 吴裕雄--天生自然MySQL学习笔记:MySQL 连接
使用mysql二进制方式连接 您可以使用MySQL二进制方式进入到mysql命令提示符下来连接MySQL数据库. 实例 以下是从命令行中连接mysql服务器的简单实例: [root@host]# my ...
- EditText制作简单的登录界面
EditText与之前的TextView和Button的用法大体相同,用法案例如下: activity_edit_text.xml: <?xml version="1.0" ...
- goahead调试经验
一.参考网址 1.源码的github地址 2.Web开发之Goahead 二.技术细节 1.默认网页的存放目录和名称 1)目录:在main.c文件中有*rootWeb定义,如: 2)网页名:在mai ...
- 基于ssh开发彩票购买系统的设计与实现毕业设计
开发环境: Windows操作系统开发工具: MyEclipse+Jdk+Tomcat+MYSQL数据库 运行效果图: 源码及原文地址:http://javadao.xyz/forum.php?mod ...
- Go 验证是否字符串包含中文
发现一个验证字符串是否包含中文滴时候,一个比正则更好使滴方法,而且是golang 自带滴验证. 不需要自己写正则验证,代码如下: package main import ( "fmt&quo ...
- 安装使用离线版本的维基百科(Wikipedia)
1 相关背景 平常大家在上网查询一些基本概念的时候常常会参考维基百科上面的资料,但是由于方校长研制的GFW(长城防火墙系统)强大的屏蔽功能,好多链接打开以后,不出意外会出现著名的“404NOT FOU ...
- 浅谈对RabbitMQ的认识
一.什么是消息队列?什么时候使用它? 在传统的web架构中(此处特指Java SSM架构),用户在web中进行了某项需要和后台产生交互的操作后,一般都要开启一个session,从view层开始,由co ...
- latex学习笔记----数学公式
https://www.jianshu.com/p/d7c4cf8dc62d 1.数学公式在 \( 和 \)之间,$和$之间,或者\begin{math}和\end{math}之间 2.对于较大 ...
- 题解【DP100题1~10】
哎~这事做晚了~ (Dp100计划T1) 只有蓝题及以上才会水题解 分行Dp,行间没有转移 \[ F[L][R] = max(F[L+1][R]+2^k \times V[L],F[L][R-1]+2 ...
- SQL查询出一个表数据插入到另一个表里
下面两中方式都是将 srcTbl 的数据插入到 destTbl,但两句又有区别的: 方式一 (select into from)要求目标表(destTbl)不存在,因为在插入时会自动创建. selec ...