Ruby oneliner


  • 0
    def optimal_division(nums)
      nums.join("/").sub(%r{/(.*/.*)}, '/(\1)')
    end
    

    Using a regular expression to turn something like "4/5/6/7" into "4/(5/6/7)".


Log in to reply
 

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