1. 描述

In tennis, the winner of a set is based on how many games each player wins. The first player to win 6 games is declared the winner unless their opponent had already won 5 games, in which case the set continues until one of the players has won 7 games.
在网球比赛中,每局的胜负取决于每位选手赢了多少局。第一个赢得 6 局的玩家被宣布为获胜者,除非他们的对手已经赢得了 5 局,在这种情况下,该局将继续进行,直到其中一名玩家赢得 7 局。

Given two integers score1 and score2, your task is to determine if it is possible for a tennis set to be finished with a final score of score1 : score2.
给定两个整数 score1 和 score2 ,您的任务是确定网球组是否有可能以 score1 : score2 的最终比分结束。

2. 例子

  • For score1 = 3 and score2 = 6, the output should be
    对于 score1 = 3 和 score2 = 6 ,输出应该是
    solution(score1, score2) = true.  solution(score1, score2) = true 。

    Since player 1 hadn’t reached 5 wins, the set ends once player 2 has won 6 games.
    由于玩家 1 尚未达到 5 胜利,一旦玩家 2 赢得了 6 场比赛,该盘就结束了。

  • For score1 = 8 and score2 = 5, the output should be
    对于 score1 = 8 和 score2 = 5 ,输出应该是
    solution(score1, score2) = false.  solution(score1, score2) = false 。

    Since both players won at least 5 games, the set would’ve ended once one of them won the 7th one.
    由于两名球员都至少赢得了 5 场比赛,因此一旦其中一名球员赢得了 7th 场比赛,比赛就结束了。

  • For score1 = 6 and score2 = 5, the output should be
    对于 score1 = 6 和 score2 = 5 ,输出应该是
    solution(score1, score2) = false.  solution(score1, score2) = false 。

    This set will continue until one of these players wins their 7th game, so this can’t be the final score.
    这盘比赛将持续到其中一名球员赢得他们的 7th 比赛,所以这不是最终比分。

3. 思路

主要还是逻辑判断,根据题目的要求来分析:

  1. 谁先到达 6,且对手小于 5,完成比赛
  2. 否则,如果有一个到了 5,就得要求对手到 7
  3. 其它的情况都是 False

4. 代码

if max(score1, score2) == 6 and min(score1, score2)<5:
	return True
elif 5<=min(score1,score2)<=6 and max(score1,score2)==7:
	return True
else:
	return False

再来一行代码的:

return True if max(score1,score2)==6 and min(score1,score2)<5 else True if 5<=min(score1,score2)<= 6 and max(score1,score2)==7 else False