856. Score of Parentheses——string

class Solution(object):
    def repeatedNTimes(self, S):
        num = 0
        tmp = S[0]
        a = []
        for i in range(len(S)):
            if S[i] == "(":
                tmp = "("
                a.append("(")
            elif tmp == "(" and S[i] == ")":
                num += 2**(len(a)-1)
                tmp = ")"
                a.pop()
            elif tmp == ")" and S[i] == ")":
                a.pop()
        return num

相关文章:

  • 2021-05-24
  • 2021-09-18
  • 2022-12-23
  • 2021-11-24
  • 2021-12-03
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-08-27
  • 2021-12-31
  • 2022-12-23
相关资源
相似解决方案