카카오_해커랭크_easy 10p_Breaking the Records_구현

RostoryT·2022년 7월 13일
0



메모한 것

  • 너무 쉬운 문제라 금방 품

솔루션 코드 - 실행용

def breakingRecords(n, scores):
    high_score = scores[0]
    low_socre = scores[0]
    max_num = min_num = 0    
    
    for i in range(1, n):
        if scores[i] < low_socre:
            low_socre = scores[i]
            min_num += 1
        if high_score < scores[i]:
            high_score = scores[i]
            max_num += 1
            
    return [max_num, min_num]
    
n = 10
scores = [3, 4, 21, 36, 10, 28, 35, 5, 24, 42]
print(" ".join(map(str, breakingRecords(n, scores))))


솔루션 코드 - 제출용

#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'breakingRecords' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts INTEGER_ARRAY scores as parameter.
#

def breakingRecords(n, scores):
    high_score = scores[0]
    low_socre = scores[0]
    max_num = min_num = 0    
    
    for i in range(1, n):
        if scores[i] < low_socre:
            low_socre = scores[i]
            min_num += 1
        if high_score < scores[i]:
            high_score = scores[i]
            max_num += 1
            
    return [max_num, min_num]

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input().strip())

    scores = list(map(int, input().rstrip().split()))

    result = breakingRecords(n, scores)

    fptr.write(' '.join(map(str, result)))
    fptr.write('\n')

    fptr.close()

profile
Do My Best

0개의 댓글