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 determine if the starting player can guarantee a win.
For example, givens = "++++", return true. The starting player can guarantee a win by flipping the middle"++"to become"+--+".
Follow up: ?Derive your algorithm's runtime complexity.
思路是先反轉(zhuǎn)一下, 判斷對(duì)手輸贏狀態(tài), 把剛剛反轉(zhuǎn)的回溯成最初的字符串饺汹, 免得影響下一個(gè)循環(huán)結(jié)果端仰。 如果確定對(duì)手輸了暇赤, 那我們一定贏了响巢, 直到循環(huán)結(jié)束厅缺,都沒發(fā)現(xiàn)對(duì)手輸罢吃, 那一定是我們輸了楚午。