# 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 findSecondMinimumValue(self, root):
"""
:type root: TreeNode
:rtype: int
"""
nums = set()
def dfs(root):
if not root:
return
dfs(root.left)
dfs(root.right)
dfs(root)
return -1 if len(nums)<2 else sorted(list(nums))[1]


# 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 trimBST(self, root, L, R):
"""
:type root: TreeNode
:type L: int
:type R: int
:rtype: TreeNode
"""
if not root:
return None
if root.val < L:
return self.trimBST(root.right, L, R)
if root.val > R:
return self.trimBST(root.left, L, R)
root.left = self.trimBST(root.left, L, R)
root.right = self.trimBST(root.right, L, R)
return root


class Solution(object):
def maximumSwap(self, num):
"""
:type num: int
:rtype: int
"""
if num == 0:
return 0
ln = []
while num > 0:
ln.append(num % 10)
num /= 10
ln = ln[::-1]
tmp = sorted(ln, key=lambda x: -x)
i = 0
while i < len(ln) and ln[i] == tmp[i]:
i += 1
if i < len(ln):
j = len(ln)-1
while ln[j] != tmp[i]:
j -= 1
ln[i], ln[j] = ln[j], ln[i]
ans = 0
p = 1
for n in ln[::-1]:
ans += n*p
p *= 10
return ans


class Solution(object):
def maximumSwap(self, num):
"""
:type num: int
:rtype: int
"""
ans = num
num = str(num)
for i in xrange(len(num)):
for j in xrange(i+1, len(num)):
c = list(num)
c[i], c[j] = c[j], c[i]
ans = max(ans, int(''.join(c)))
return ans


1. 改变所有灯的状态；
2. 改变所有偶数的灯的状态；
3. 改变所有奇数的灯的状态；
4. 改变所有(3k+1)的灯的状态。

class Solution(object):
def flipLights(self, n, m):
"""
:type n: int
:type m: int
:rtype: int
"""
ans = set([15])
btn = [15, 10, 9, 5]
mask = (1 << min(n, 4)) - 1
for i, n in enumerate(btn):