본문 바로가기
알고리즘

[HackerRank] Breaking the Records (PYTHON)

by VIPeveloper 2021. 11. 1.
반응형

문제 링크 : https://www.hackerrank.com/challenges/breaking-best-and-worst-records/problem

 

Breaking the Records | HackerRank

Given an array of Maria's basketball scores all season, determine the number of times she breaks her best and worst records.

www.hackerrank.com

최고기록을 갱신 시마다 업데이트 시켜주는 것이 중요하다는 것을 알게 되었습니다.

def breakingRecords(scores):
    # Write your code here
    win_cnt, lose_cnt = 0,0
    breaking_win,breaking_lose = scores[0],scores[0]
    for i in range(1,len(scores)):
        if scores[i] > breaking_win:
            win_cnt += 1
            breaking_win = scores[i]
        if scores[i] < breaking_lose:
            lose_cnt += 1
            breaking_lose = scores[i]
    return win_cnt, lose_cnt

 

반응형