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 [].

 class Solution {
public:
vector<string> generatePossibleNextMoves(string s) {
vector<string> res;
for (int i = , n = s.size() - ; i < n; i++)
if (s[i] == '+' && s[i + ] == '+') {
string temp = s;
temp[i] = temp[i + ] = '-';
res.push_back(temp);
}
return res;
}
};

Flip Game -- LeetCode的更多相关文章

  1. [LeetCode] Flip Game 翻转游戏之二

    You are playing the following Flip Game with your friend: Given a string that contains only these tw ...

  2. [LeetCode] Flip Game 翻转游戏

    You are playing the following Flip Game with your friend: Given a string that contains only these tw ...

  3. LeetCode Flip Game II

    原题链接在这里:https://leetcode.com/problems/flip-game-ii/ 题目: You are playing the following Flip Game with ...

  4. LeetCode Flip Game

    原题链接在这里:https://leetcode.com/problems/flip-game/ 题目: You are playing the following Flip Game with yo ...

  5. [LeetCode] Flip Game II 翻转游戏之二

    You are playing the following Flip Game with your friend: Given a string that contains only these tw ...

  6. #Leetcode# 951. Flip Equivalent Binary Trees

    https://leetcode.com/problems/flip-equivalent-binary-trees/ For a binary tree T, we can define a fli ...

  7. LeetCode 293. Flip Game

    原题链接在这里:https://leetcode.com/problems/flip-game/description/ 题目: You are playing the following Flip ...

  8. [LeetCode] 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), ...

  9. LeetCode 971. Flip Binary Tree To Match Preorder Traversal

    原题链接在这里:https://leetcode.com/problems/flip-binary-tree-to-match-preorder-traversal/ 题目: Given a bina ...

随机推荐

  1. Vue_自定义指令

    关于Vue的自定义指令: - 在Vue中除了核心功能默认内置的指令(v-model & v-show) - Vue也允许注册自定义指令. 注意,在 Vue2.0 中,代码复用和抽象的主要形式是 ...

  2. 指定user镜像安装的磁盘

    ironic node-update <node uuid> add properties/root_device='{"name":"/dev/sdb&qu ...

  3. sdram之乒乓操作

    在实时显示时,为了保证画面显示的完整性需要对SDRAM进行乒乓操作. SDRAM 中有 4 个bank ,地址分别为00 01 10 11,后面将用 0 1 2 3来描述 bank 0和1 作为第一个 ...

  4. hnust 最小的x

    问题 G: 最小的x 时间限制: 1 Sec  内存限制: 128 MB提交: 2347  解决: 1155[提交][状态][讨论版] 题目描述 TSQ对DK进行地狱式训练,找出满足下面公式的最小的x ...

  5. 调整CodeIgniter错误报告级别

    修改位置:CI根目录 index.php 为开发环境与生产环境定义错误报告级别 if (defined('ENVIRONMENT')) { switch (ENVIRONMENT) { case 'd ...

  6. [Leetcode/Javascript] 461.Hamming Distance

    [Leetcode/Javascript] 461.Hamming Distance 题目 The Hamming distance between two integers is the numbe ...

  7. SPOJ AMR10I Dividing Stones

    Time limit: 7s Source limit: 50000B Memory limit: 256MB The first line contains the number of test c ...

  8. J2EE的十三个技术——EJB之概述

    含义: 企业级的JavaBeans(Enterprise JavaBean),其设计目标是部署分布式应用程序. EJB是J2EE的一部分,称为Java企业Bean,它把使用Java开发的服务器组件的部 ...

  9. PHP面向对象单例模式(懒汉式)

    知识点: 一.三私一公: ①.私有静态属性,又来储存生成的唯一对象 ②.私有构造函数 ③.私有克隆函数,防止克隆——clone ④.公共静态方法,用来访问静态属性储存的对象,如果没有对象,则生成此单例 ...

  10. nf_register_hooks解读

    nf_register_hooks是什么 net->netns_nf->nf_hook_entry[NFPROTO_NUMPROTO][NF_MAX_HOOKS=8] (nf)       ...