【Leetcode】1033. Moving Stones Until Consecutive
【Leetcode】1033. Moving Stones Until Consecutive

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]

相关文章:

  • 2021-06-08
  • 2021-10-12
  • 2021-11-14
  • 2021-09-03
  • 2021-07-07
  • 2021-08-15
猜你喜欢
  • 2021-09-29
  • 2021-09-07
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
相关资源
相似解决方案