LeetCode 293. Flip Game(反转游戏)
来源:互联网 发布:改革开放问题 知乎 编辑:程序博客网 时间:2024/05/16 12:33
原题网址:https://leetcode.com/problems/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 twoconsecutive "++"
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 []
.
方法:直接扫描,时间复杂度O(n)
public class Solution { public List<String> generatePossibleNextMoves(String s) { List<String> results = new ArrayList<>(); char[] sa = s.toCharArray(); for(int i=0; i<sa.length-1; i++) { if (sa[i]=='+' && sa[i+1]=='+') { sa[i]='-'; sa[i+1]='-'; results.add(new String(sa)); sa[i]='+'; sa[i+1]='+'; } } return results; }}
0 0
- LeetCode 293. Flip Game(反转游戏)
- LeetCode 294. Flip Game II(反转游戏II)
- 【Leetcode】 Flip Game 翻转游戏
- LeetCode 293. Flip Game
- Leetcode Everyday: 293. Flip Game
- Leetcode 293. Flip Game & 294. Flip Game II
- Flip Game翻转游戏
- [leetcode] 293. Flip Game 解题报告
- Leetcode 293. Flip Game (Easy) (cpp)
- [Leetcode] 293. Flip Game 解题报告
- [LeetCode 293] Flip Game
- *LeetCode-Flip Game II
- [leetcode 293] Flip Game
- Leetcode 293: Flip Game
- Leetcode: Flip Game
- [LeetCode 293] Flip Game
- poj--1753 Flip Game(二维反转)(高斯消元)
- LeetCode 题解(276) :Flip Game
- LeetCode 290. Word Pattern(单词模式)
- LeetCode 56. Merge Intervals
- LeetCode 292. Nim Game(取物游戏)
- java泛型的使用(一)定义类时,使用泛型
- java泛型的使用(二)在实例化对象时不指定泛型,则自动识别为object
- LeetCode 293. Flip Game(反转游戏)
- java泛型的使用(三)通配符的使用
- java泛型的使用(四)设置泛型的时候,只能是Number或者Number的子类(int,float)等
- java泛型的使用(五)在接口中定义泛型
- java泛型的使用(六)在方法中使用泛型
- JS去掉空格
- 说反话
- 具有弹性的ListView
- 2016 电子竞技市场概论