ruby solution in 7 lines


  • 0
    T
    # @param {String} num
    # @return {Boolean}
    def is_strobogrammatic(num)
      return true if num.length == 0
      a, b = num[0], num[-1]
      sets = [['8','8'],['6','9'],['0','0'],['1','1']]
      sets.each do |set|
        return is_strobogrammatic(num[1..-2]) if (a == set[0] && b == set[1]) || (a == set[1] && b == set[0])
      end
      return false
    end
    

Log in to reply
 

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