Skip to content

Instantly share code, notes, and snippets.

@deppyu
Created February 24, 2014 07:17
Show Gist options
  • Save deppyu/9183277 to your computer and use it in GitHub Desktop.
Save deppyu/9183277 to your computer and use it in GitHub Desktop.
计算一个数字的出现1的次数
def counter(n)
return 0 if n<=0
(n%10) == 1 ? 1+counter(n/10) : counter(n/10)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment