Ruby is so nice ("1-liner")


  • 0

    Not a 100% serious solution for this problem, but I only just learned that Ruby has this, and wanted to share. Can maybe be useful in some other problems.

    require 'prime'
    
    def count_primes(n)
      Prime.each(n-1).count
    end
    

    Not surprisingly, it's also fast. Four out of five times I submitted it, it was faster than all other Ruby submissions.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.