python练习1708

def myPow(x, n):
    return math.pow(x, n)
def superPow(a, b):
    x = 0
    for i in b:
        x = x * 10 + i
    return pow(a, x, 1337)
def isValid(s):
    v = []
    d = {")":"(", "]":"[", "}":"{"}
    for i in s:
        if i in d.values():
            v.append(i)
        elif i in d.keys():
            if len(v) == 0 or d[i] != v.pop():
                return False
        else:
            return False
    return len(v) == 0
def generateParenthesis(n):
    def gen(s, nl, nr, v = []):
        if nr == 0:  v.append(s)
        if nl > 0:   gen(s + '(', nl - 1, nr, v)
        if nr > nl:  gen(s + ')', nl, nr - 1, v)
        return v
    return gen('', n, n)
Table of Contents