# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
def findDuplicateSubtrees(self, root):
"""
:type root: TreeNode
:rtype: List[TreeNode]
"""
seen = {}
def dfs(root):
if not root:
return ''
left = dfs(root.left)
right = dfs(root.right)
s = '{}({})({})'.format(root.val, left, right)
if s not in seen:
seen[s] = [1, root]
else:
seen[s][0] += 1
return s
dfs(root)
ans = []
for c, node in seen.values():
if c > 1:
ans.append(node)
return ans


• 复制：复制笔记本所有字符
• 粘贴：粘贴最新一次的复制

1. 首先从记事本的那个'A', 计算得到a个'A'的最小次数；
2. 然后将记事本中的那a个'A'当作一个整体s，计算得到b个s的最小次数。

class Solution(object):
def minSteps(self, n):
"""
:type n: int
:rtype: int
"""
f = [0] * (n+1)
for k in xrange(2, n+1):
f[k] = k
for i in xrange(2, k):
if k % i != 0:
continue
f[k] = min(f[i]+f[k/i], f[k])
return f[n]


class Solution(object):
def predictPartyVictory(self, senate):
"""
:type senate: str
:rtype: str
"""
s = [1 if c=='R' else 0 for c in senate]
c = sum(s)
while c!=0 and c!=len(s):
rd = [0, 0]
t = []
for i in s:
if rd[1-i] > 0:
rd[1-i] -= 1
else:
rd[i] += 1
t.append(i)
s = []
for i in t:
if rd[1-i] > 0:
rd[1-i] -= 1
else:
s.append(i)
c = sum(s)
return 'Dire' if c==0 else 'Radiant'


(A): 在屏幕打印一个'A'；
(Ctrl-A): 选择整个屏幕；
(Ctrl-C): 复制选择的区域；
(Ctrl-V): 将复制的内容打印到现有的字符后面。

f[i]+f[i]*f[n-i-2]

class Solution(object):
def maxA(self, N):
"""
:type N: int
:rtype: int
"""
f = [0] * (N+1)
for n in xrange(1, N+1):
f[n] = n
for i in xrange(n-2):
f[n] = max(f[i]+f[i]*f[n-i-2], f[n])
return f[N]