LeetCode Solutions

1033. Moving Stones Until Consecutive

Time:

Space:

			

class Solution {
 public:
  vector<int> numMovesStones(int a, int b, int c) {
    vector<int> nums = {a, b, c};

    sort(begin(nums), end(nums));

    if (nums[2] - nums[0] == 2)
      return {0, 0};
    return {min(nums[1] - nums[0], nums[2] - nums[1]) <= 2 ? 1 : 2,
            nums[2] - nums[0] - 2};
  }
};
			

class Solution {
  public int[] numMovesStones(int a, int b, int c) {
    int[] nums = new int[] {a, b, c};

    Arrays.sort(nums);

    if (nums[2] - nums[0] == 2)
      return new int[] {0, 0};
    return new int[] {Math.min(nums[1] - nums[0], nums[2] - nums[1]) <= 2 ? 1 : 2,
                      nums[2] - nums[0] - 2};
  }
}
			

class Solution:
  def numMovesStones(self, a: int, b: int, c: int) -> List[int]:
    nums = sorted([a, b, c])

    if nums[2] - nums[0] == 2:
      return [0, 0]
    return [1 if min(nums[1] - nums[0], nums[2] - nums[1]) <= 2 else 2,
            nums[2] - nums[0] - 2]