일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Python
- MySQL
- Artificial Intelligence
- leetcode
- multimodal machine learning
- error
- Anaconda
- 코딩테스트
- autogluon
- jmeter
- memory bank
- Linux
- q-former
- hackerrank
- LeNet-5
- Github
- CNN
- timechat
- long video understanding
- quantification
- Server
- timestamp-aware frame encoder
- ma-lmm
- transference
- Kaggle
- secure-file-priv
- 백준
- 용어
- tensorflow
- sliding video q-former
- Today
- Total
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Python
- MySQL
- Artificial Intelligence
- leetcode
- multimodal machine learning
- error
- Anaconda
- 코딩테스트
- autogluon
- jmeter
- memory bank
- Linux
- q-former
- hackerrank
- LeNet-5
- Github
- CNN
- timechat
- long video understanding
- quantification
- Server
- timestamp-aware frame encoder
- ma-lmm
- transference
- Kaggle
- secure-file-priv
- 백준
- 용어
- tensorflow
- sliding video q-former
- Today
- Total
Juni_DEV
[Python, HackerRank] Breaking the Records 본문
주어진 문제
Maria plays college basketball and wants to go pro. Each season she maintains a record of her play. She tabulates the number of times she breaks her season record for most points and least points in a game. Points scored in the first game establish her record for the season, and she begins counting from there.
Example
scores = [12,24,10,24]
Scores are in the same order as the games played. She tabulates her results as follows:
Count
Game Score Minimum Maximum Min Max
0 12 12 12 0 0
1 24 12 24 0 1
2 10 10 24 1 1
3 24 10 24 1 1
Given the scores for a season, determine the number of times Maria breaks her records for most and least points scored during the season.
Function Description
Complete the breakingRecords function in the editor below.
breakingRecords has the following parameter(s):
- int scores[n]: points scored per game
Returns
- int[2]: An array with the numbers of times she broke her records. Index 0 is for breaking most points records, and index 1 is for breaking least points records.
Input Format
The first line contains an integer , the number of games.
The second line contains space-separated integers describing the respective values of score0, score1, ..., score (n-1).
Constraints
- 1<= n <= 1000
- 0<= score[i] <= 10^8
풀이
def breakingRecords(scores):
# Write your code here
max_sc, min_sc = -1,100000001
max_ans, min_ans = 0,0
for sc in scores :
if sc > max_sc :
max_sc = sc
max_ans +=1
if sc < min_sc :
min_sc = sc
min_ans +=1
return max_ans-1, min_ans-1
맨 처음에 max_sc, min_sc 초기화할 때 0,0으로 값을 설정했더니 score[0] 값이 0인 경우에 문제가 생김
-> 그래서 주어진 scores[i] 범위에 따라 -1, 100000001로 설정하고
맨 처음 더해지는 1을 return 할 때 빼주는 식으로 번거롭게 했는데
==> 이럴게 아니라 그냥 score[0] 값으로 초기화를 하면 된다.
풀이2
def breakingRecords(scores):
# Write your code here
max_sc, min_sc = scores[0], scores[0]
max_ans, min_ans = 0,0
for sc in scores :
if sc > max_sc :
max_sc = sc
max_ans +=1
if sc < min_sc :
min_sc = sc
min_ans +=1
return max_ans, min_ans
'Coding Interview' 카테고리의 다른 글
[Python, HackerRank] Camel Case 4 (0) | 2023.04.19 |
---|---|
[Python, LeetCode] 9. Palindrome Number (0) | 2023.04.14 |
[Python, LeetCode] 1. Two Sum (0) | 2023.04.14 |
[Python, HackerRank] Mini-Max Sum (0) | 2023.04.13 |
[Python, HackerRank] Time-conversion (0) | 2023.04.13 |