1 Star 0 Fork 0

徐长贺/Leetcode

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
_293.java 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
Fisher Coder 提交于 2018-12-02 23:18 +08:00 . refactor 293
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.List;
/**
* 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.
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 [].*/
public class _293 {
public static class Solutoin1 {
public List<String> generatePossibleNextMoves(String s) {
List<String> result = new ArrayList<>();
for (int i = 1; i < s.length(); i++) {
if (s.charAt(i) == '+' && s.charAt(i - 1) == '+') {
result.add(s.substring(0, i - 1) + "--" + s.substring(i + 1));
}
}
return result;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/isulong/Leetcode.git
git@gitee.com:isulong/Leetcode.git
isulong
Leetcode
Leetcode
master

搜索帮助