- 안녕하세요. 오랜만에 돌아왔습니다.
- 그 동안 물갈이에다 장염이 걸려서 참 오랫동안 누워있었고... (거의 일주일간 ㅠㅠ )
- 이제야 정신을 차렸네요.
- 오늘은 HackerRank에 있는 문제를 가져왔구요.
- 푸는 건 빠르게 풀었는데 이렇게 푸는게 맞나? 싶긴 합니다..
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'birthdayCakeCandles' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY candles as parameter.
#
def birthdayCakeCandles(candles):
largest = 0
count = 0
for n in candles:
# print(n) # 3 2 1 3
if n > largest:
largest = n
for n in candles:
if n == largest:
count+=1
return 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()
- 반복문을 두 번 돌려서
- 제일 큰 값을 찾아낸다
- 그 값과 같은 값의 개수를 센다
- 이런 식으로 접근했는데, 훨씬 더 편하게 접근할 수 있는 방식이 있지 않나? 싶긴 합니다..
'Programming > 1 Day 1 Commit' 카테고리의 다른 글
[BaekJoon] 2798번: 블랙잭 (Python3) (0) | 2023.04.14 |
---|---|
[Programmers] 자연수 뒤집어 배열로 만들기 (0) | 2023.02.10 |
[LeetCode] Add Two Numbers (Python3) (0) | 2023.01.31 |
[BaekJoon] 17413번: 단어뒤집기 2 (Python3) (0) | 2023.01.27 |
[HackerRank] Mini-Max Sum (Python3) (0) | 2023.01.26 |