물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

Odd or Even?

BEstyle 2022. 9. 23. 13:04

DESCRIPTION:

Task:

Given a list of integers, determine whether the sum of its elements is odd or even.

Give your answer as a string matching "odd" or "even".

If the input array is empty consider it as: [0] (array with a zero).

Examples:

Input: [0]
Output: "even"

Input: [0, 1, 4]
Output: "odd"

Input: [0, -1, -5]
Output: "even"

Have fun!


def odd_or_even(arr):
    return "even" if sum(arr)%2==0 else "odd"

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

Build a pile of Cubes  (0) 2022.09.26
Two Sum  (0) 2022.09.23
Highest Scoring Word  (1) 2022.09.23
Mexican Wave  (0) 2022.09.23
Find the unique number  (0) 2022.09.23