Mr Shang

我是一个勤劳的码农,每天在技术的牧场辛勤劳作


导航栏
 » 首页
 » 分类浏览
 » 关于我
 » 我的Github
 » RSS订阅
Group 59

Find the number of even digits in the given integer [CF]

10 Jun 2016 » python, codefights

Find the number of even digits in the given integer.

Example

  • For n = 1010, the output should be numberOfEvenDigits(n) = 2.
  • For n = 123, the output should be numberOfEvenDigits(n) = 1.

Input/Output

  • [time limit] 4000ms (py)
  • [input] integer n (A positive integer).

Constraints:

  • 1 ≤ n ≤ 106.

  • [output] integer

My Solution:

def numberOfEvenDigits(n):
    return len(filter(lambda m: m.isdigit() and int(m) % 2 == 0, str(n)))

Rests Tests:

n: 1010
Output: 2

n: 123
Output: 1

n: 135
Output: 0
© Mr Shang - niceshang[#]outlook.com - Powered by Jekyll.