ある配列があり、その中にあらわれる異なる数字の個数を数えるにはどう書けばよいですか?
ただし、同じ数字が二回以上出てきたら、0をかえすことにします。
ruby
1def count_distinct_numbers(ary) 2??? 3end 4 5p count_distinct_numbers([1, 2, 3, 5, 8]) #=> 5 6p count_distinct_numbers([1, 1, 2, 3, 5, 8]) #=> 0
回答3件
あなたの回答
tips
プレビュー
投稿2017/05/10 14:18
編集2017/05/10 14:21ある配列があり、その中にあらわれる異なる数字の個数を数えるにはどう書けばよいですか?
ただし、同じ数字が二回以上出てきたら、0をかえすことにします。
ruby
1def count_distinct_numbers(ary) 2??? 3end 4 5p count_distinct_numbers([1, 2, 3, 5, 8]) #=> 5 6p count_distinct_numbers([1, 1, 2, 3, 5, 8]) #=> 0
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。