class Solution(object):
def numMovesStones(self, a, b, c):
"""
the max is easy to get, the max equals to the farthest minus the nearest minus 2
for the case min, there are two cases:
1. special case, like 1 3 5, the adjacent element's distance is and we just need to the third one(no matter the third one adjacent or not)
2. general case, min(c-b, 1) + min(b-c,1)
"""
a,b,c = sorted([a,b,c])
maxer = c - a -2
miner = 1 if c - b == 2 or b - a == 2 else min(c-b-1,1) + min(b-a-1,1)
return [miner, maxer]
相关文章: