반응형
Messi goals function
Messi is a soccer player with goals in three leagues:
- LaLiga
- Copa del Rey
- Champions
Complete the function to return his total number of goals in all three leagues.
Note: the input will always be valid.
For example:
5, 10, 2 --> 17
Solution:
int goals(int laLigaGoals, int copaDelReyGoals, int championsLeagueGoals) {
return add_nums([laLigaGoals, copaDelReyGoals, championsLeagueGoals]);
}
int add_nums(List<int> nums) {
int result = 0;
for (int num in nums) {
result += num;
}
return result;
}
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1124. Beginner Series #2 Clock (0) | 2022.11.24 |
---|---|
1123. L1: Set Alarm (0) | 2022.11.24 |
1121. Grasshopper - Grade book (0) | 2022.11.22 |
1120. Determine offspring sex based on genes XX and XY chromosomes (0) | 2022.11.20 |
1119. Return Negative (0) | 2022.11.19 |