1. 整数：代表本轮得分
2. "+"：本轮得分为上两轮得分之和
3. "D"：本轮得分为上轮得分的两倍
4. "C"：上轮得分无效。

class Solution(object):
def calPoints(self, ops):
"""
:type ops: List[str]
:rtype: int
"""
points = []
for op in ops:
if op == 'C':
points.pop()
elif op == 'D':
points.append(points[-1]*2)
elif op == '+':
points.append(points[-1]+points[-2])
else:
points.append(int(op))
return sum(points)


class Solution(object):
def nextClosestTime(self, time):
"""
:type time: str
:rtype: str
"""
timestamp = int(time[:2]) * 60 + int(time[-2:])
digits = map(int, list(time.replace(':', '')))
candidate = set()
for i, j, k, l in itertools.product(digits, repeat=4):
if 10*i+j < 24 and 10*k+l < 60:
time_diff = 600*i+60*j+10*k+l
time_diff -= timestamp
if time_diff <= 0:
time_diff += 24*60

return sorted(candidate)[0][1]


class Solution(object):
def findRedundantConnection(self, edges):
"""
:type edges: List[List[int]]
:rtype: List[int]
"""
f = [-1] * 2001
def father(i):
if f[i] == -1:
return i
f[i] = father(f[i])
return f[i]
for u, v in edges:
fu = father(u)
fv = father(v)
if fu == fv:
return [u, v]
f[fv] = fu


a[x+1]+...+a[y-1]=0

class Solution(object):
def kEmptySlots(self, flowers, k):
"""
:type flowers: List[int]
:type k: int
:rtype: int
"""
n = len(flowers)
bit = [0] * (n+1)
def update(i):
while i <= n:
bit[i] += 1
i += (i & -i)

def query(i):
ans = 0
while i > 0:
ans += bit[i]
i -= (i & -i)
return ans

bloomed = set()
for d, x in enumerate(flowers):
update(x)
if x+k+1 in bloomed and query(x+k+1)==query(x)+1:
return d+1
if x-k-1 in bloomed and query(x)==query(x-k-1)+1:
return d+1