464. Can I Win

class Solution(object):
    def canIWin(self, maxChoosableInteger, desiredTotal):
        """
        :type maxChoosableInteger: int
        :type desiredTotal: int
        :rtype: bool
        """
        if sum(range(1,maxChoosableInteger+1))=desiredTotal:
            self.memo[array_hash]=True
            return True
            
        #pick a number, if the opponent can't force a win with the rest, that means i can force a win with picking this number 
        for i in xrange(len(array)):
            if not self.helper(array[:i]+array[i+1:],desiredTotal-array[i]):
                self.memo[array_hash]=True
                return True 
        #if there is no number that i can pick to force a win, then this array, total combination is false. 
        self.memo[array_hash]=False
        return False
            
    
            

你可能感兴趣的:(464. Can I Win)