나는 이렇게 학습한다/Algorithm & SQL

1122. Grasshopper - Messi goals function

daco2020 2022. 11. 22. 20:35
반응형

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;
}


반응형