Fourth Flip Game II

Source: Internet
Author: User

1  Public classSolution {2     Public BooleanCanwin (String s) {3         if(s = =NULL|| S.length () <= 1) {4             return false;5         }6Arraylist<string> validmoves =getvalidmoves (s);7         if(Validmoves.isempty ()) {8             return false;9         }Ten          for(String str:validmoves) { One             if(!Canwin (str)) { A                 return true; -             } -         } the         return false; -     } -      -     PrivateArraylist<string>getvalidmoves (String s) { +arraylist<string> result =NewArrayList (); -          for(inti = 0; I < S.length ()-1; i++) { +             if(S.charat (i) = = ' + ' && s.charat (i + 1) = = ' + ') { A                 Char[] tmp =S.tochararray (); atTmp[i] = '-'; -Tmp[i + 1] = '-'; -Result.add (NewString (TMP)); -             } -         } -         returnresult; in     } -}

Google face by Topic

Before and Cong Meow review LinkedIn face through can I win, the same idea can also be used in this problem

This kind of rotating game problem can also be solved using the enumeration method, the key is the 11th row!canwin (str), indicating that the current selection of opponents must lose, then the current selection is the winning strategy

Fourth Flip Game II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.