日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

leetcode 293.Flip Game(lintcode 914) 、294.Flip Game II(lintcode 913)

發(fā)布時間:2025/7/14 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 leetcode 293.Flip Game(lintcode 914) 、294.Flip Game II(lintcode 913) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

914. Flip Game

https://www.cnblogs.com/grandyang/p/5224896.html

從前到后遍歷,遇到連續(xù)兩個'+',就將兩個加號變成'-'組成新的字符串加入到結(jié)果中。

class Solution { public:vector<string> generatePossibleNextMoves(string &s) {// write your code herevector<string> result; for(int i = 1;i < s.size();i++){if(s[i] == '+' && s[i-1] == '+')result.push_back(s.substr(0,i-1) + "--" + s.substr(i+1,s.size() - i - 1));}return result;} };

?

?913.?Flip Game II

這個題是看先手變換的是否會贏。

方法與Flip Game類似,遍歷字符串,然后遞歸找下一個是否是能修改,將修改后的字符串傳入到遞歸的結(jié)果中。

https://www.cnblogs.com/grandyang/p/5226206.html

下面這個應(yīng)該是leetcode上的格式,沒有使用引用,這個代碼直接貼到lintcode上會報錯。

class Solution { public:bool canWin(string s) {for (int i = 1; i < s.size(); ++i) {if (s[i] == '+' && s[i - 1] == '+' && !canWin(s.substr(0, i - 1) + "--" + s.substr(i + 1))) {return true;}}return false;} };

修改后lintcode上的代碼。

class Solution { public:/*** @param s: the given string* @return: if the starting player can guarantee a win*/bool canWin(string &s) {// write your code herefor(int i = 1;i < s.size();i++){if(s[i] == '+' && s[i-1] == '+'){string tmp = s.substr(0,i-1) + "--" + s.substr(i+1);if(!canWin(tmp))return true;}}return false;} };

?

轉(zhuǎn)載于:https://www.cnblogs.com/ymjyqsx/p/10841419.html

總結(jié)

以上是生活随笔為你收集整理的leetcode 293.Flip Game(lintcode 914) 、294.Flip Game II(lintcode 913)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。