Algorithm/HackerRank
[HackerRank]Birthday Cake Candles(풀이 성공)
전봇대파괴자
2021. 2. 1. 23:13
문제
생일 케이크에 나이만큼 초(candle)를 꽂는다. 초의 길이는 각각 다르며, 가장 길이가 긴 초들의 불만 불어 끌 수 있다. input으로 나이 n(=초의 갯수), 각 초들의 길이가 들어있는 array가 주어진다. 그 중 불을 끌 수 있는 초들의 개수를 출력하라.
Sample Input :
4
3 2 1 3
Sample Output :
2
내 코드:
import math
import os
import random
import re
import sys
def birthdayCakeCandles(candles):
# Write your code here
max_count = candles.count(max(candles))
return max_count
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
candles_count = int(input().strip())
candles = list(map(int, input().rstrip().split()))
result = birthdayCakeCandles(candles)
fptr.write(str(result) + '\n')
fptr.close()
Comment: 리스트 내 가장 큰 값을 찾고, 그 값의 갯수를 구해 출력하면 되는 간단한 문제입니다. max와 count만 사용할 줄 안다면 쉽게 풀 수 있습니다.