Python - convert to binary int, add, then return as format string


  • 0
    G
    class Solution:
      # @param a, a string
      # @param b, a string
      # @return a string
      def addBinary(self, a, b):
          return '{0:b}'.format(int(a, 2) + int(b, 2))

  • 1
    M

    cool ! my solution is pretty similar . BTW , what was that downvote for on your question ?

    class Solution:
        # @param a, a string
        # @param b, a string
        # @return a string
        def addBinary(self, a, b):
            return bin(int (a,2) + int (b,2))[2:]

Log in to reply
 

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