CodingBat | make_bricks

链接:Make bricks问题

思路:先尽可能多地使用大的,再使用小的

1)用了多少块大的:min(big, goal / 5)

2)还需要多少块小的:goal - 5 * min(big, goal / 5)

def make_bricks(small, big, goal):
  if goal / 5 <= big:
    return goal % 5 <= small
  else:
    return goal - big * 5 <= small

更简洁的写法: 

def make_bricks(small, big, goal):
  return goal - 5 * min(big, goal/5) <= small

 

你可能感兴趣的:(CodingBat)