0
0

More than 3 years have passed since last update.

Leetcode 1295. Find Numbers with Even Number of Digits

Posted at

require 'test/unit'
require 'pry'
class FindNumbersWithEvenNumberOfDigits < Test::Unit::TestCase

  #https://leetcode.com/problems/find-numbers-with-even-number-of-digits/

  def test_calc

    nums = [12, 345, 2, 6, 7896]
    output = 2
    find_numbers(nums)

    nums = [555, 901, 482, 1771]
    output = 1
    find_numbers(nums)
  end

  def find_numbers(nums)
    count = 0
    nums.each do |num|
      if num.to_s.size % 2 == 0
        count += 1
      end
    end
    count
  end

end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0