1-liner in Ruby / Python


  • 1

    Ruby:

    def integer_break(n)
      n < 4 ? n - 1 : 3**((n-2)/3) * ((n-2)%3+2)
    end
    

    Python:

    def integerBreak(self, n):
        return n - 1 if n < 4 else 3**((n-2)/3) * ((n-2)%3+2)

  • 0
    K

    Great observation!
    It's basically a O(1) solution


Log in to reply
 

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