No.2 flip game 翻转游戏
2015-11-01 13:29
183 查看
一个字符串包含+和-;你和你朋友轮流可以将++翻转为--;当不能再翻转时获胜。
给出经过一个有效的翻转之后字符串的所有可能状态;
如果没有可行的翻转,则返回一个空字符串[];
思路:扫一遍s。判断s[i]和s[i+1]
给出经过一个有效的翻转之后字符串的所有可能状态;
如果没有可行的翻转,则返回一个空字符串[];
思路:扫一遍s。判断s[i]和s[i+1]
class Solution{ public: vector<string> getNumsOfPossibleMoves(string s){ vector<string> moves; int n=s.length(); if(n<=1) ///////////////// return moves; for(int i=0;i<n-1;i++){ if(s[i]=='+' && s[i+1]=='+') { s[i]='-'; s[i+1]='-'; moves.push_back(s); s[i]='+'; s[i+1]='+'; } } return moves; } };
相关文章推荐
- cf#328-B. The Monster and the Squirrel-水题+数学规律
- Shiro使用和源码分析---3
- 另一种导致的原因:java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/
- 【学习笔记0001】Go初学者需要关注的50个注意事项
- Intel- 64 与 IA-32架构软件开发人员手册 中文版
- Android SDK安装更新——Failed to fetch URL http://dl-ssl.google.com/android/repository/a
- No.1 Nim Game 取物游戏
- LightOJ - 1407 Explosion(2-SAT)
- 笛卡尔 变数
- SVN创建版本库
- LeetCode Excel Sheet Column Title
- 数字图像处理2--数学基础(傅立叶,拉普拉斯,卷积,差分计算)
- HDU 5531 Rebuild 相切的圆们
- 二叉树
- cf#328-A. PawnChess-水题
- ios图片拉伸技巧
- codeforces#328-C - The Big Race-乘法溢出解决办法之一 + lcm/gcd+数学
- Intel- 64 与 IA-32架构软件开发人员手册 中文版
- ios9学习系列(从微信上窃取的)
- UFT要点之同步点