41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
'''
|
|
Liam enjoys playing chess, and so does his friend Noah. One day, they played n games in a row. For each game, it is known who the winner was—Liam or Noah.
|
|
None of the games ended in a tie.
|
|
|
|
Now Liam is curious to know who won more games - him or Noah. Can you help him find out?
|
|
Given a string s, consisting of uppercase English letters L and N — the outcome of each of the games. The i-th character of the string is equal to L if the Liam
|
|
won the i-th game and N if Noah won the i-th game, return a string with Noah If Noah won more games than Liam and Liam in the opposite case. If Noah and Liam won
|
|
the same number of games, return Friendship
|
|
|
|
Example 1
|
|
Input:
|
|
LNLLLL
|
|
Output:
|
|
Liam
|
|
Example 2
|
|
Input:
|
|
NLNLNL
|
|
Output:
|
|
Friendship
|
|
Example 3
|
|
Input:
|
|
NNLNLN
|
|
Output:
|
|
Noah
|
|
'''
|
|
|
|
class Solution(object):
|
|
def solve(self, s:str) -> str:
|
|
liam_wins = s.count('L')
|
|
noah_wins = s.count('N')
|
|
if liam_wins > noah_wins:
|
|
return "Liam"
|
|
elif noah_wins > liam_wins:
|
|
return "Noah"
|
|
else:
|
|
return "Friendship"
|
|
|
|
s = Solution()
|
|
print(s.solve("LNLLLL")) # Output: Liam
|
|
print(s.solve("NLNLNL")) # Output: Friendship
|
|
print(s.solve("NNLNLN")) # Output: Noah |