Leetcode Everyday: 293. Flip Game
来源:互联网 发布:单片机引脚 编辑:程序博客网 时间:2024/05/21 07:08
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 []
.
public class Solution { public List<String> generatePossibleNextMoves(String s) { char[] c = s.toCharArray(); ArrayList<String> result = new ArrayList<String>(); if(c.length<2) return result; for(int i = 1; i<c.length ; i++){ if(c[i]=='+' && c[i-1] == '+'){ c[i-1]='-';c[i]='-'; result.add(new String(c)); c[i-1]='+';c[i]='+'; } } return result; }}
keep track the pre char, if c[i-1]=='+' && c[i] =='+', change them to '-';
0 0
- Leetcode Everyday: 293. Flip Game
- LeetCode 293. Flip Game
- Leetcode 293. Flip Game & 294. Flip Game II
- Leetcode Everyday: 292. Nim Game
- [leetcode] 293. 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
- LeetCode 题解(276) :Flip Game
- Leetcode NO.293 Flip Game
- 【Leetcode】 Flip Game 翻转游戏
- LeetCode 294. Flip Game II
- iOS mvvm 框架设计
- Xcode 读取代码所在目录txt或文件
- 关于项目开发中[VCS]版本控制
- SR 303 - Bean Validation 介绍
- React-Native系列Android——通信数据模型分析
- Leetcode Everyday: 293. Flip Game
- 总结4
- CharSequence,String ,Stringbuilder和StringBuffer源码分析
- ViewPager制作导航页
- 串模式匹配——从BF到KMP最精讲
- Linux rpm 命令参数使用详解[介绍和应用]
- JS 获取浏览器窗口大小clientWidth、offsetWidth、scrollWidth
- hdu1848(求sg)
- c语言学习笔记3之IDE