class Solution: # @param a, a string # @param b, a string # @return a string def addBinary(self, a, b): total="" sum = bin(int(a,2)+int(b,2)) for i in range(2,len(sum)): total += str(sum[i]) return total
The solution was accepted by OJ, but I am wondering if it's cheating since I used build in function from python. Thanks in advance!
It is cheating only when your interviewer thinks so. However, if you give such a solution, the interviewer will probably ask you to implement the building function(s). Remember the point is not to pass the OJ, but to demonstrate that you have understanding of algorithms or data structures. Your implement shows nothing about your understanding of element-wise addition, so it may not be what the interviewer is looking for.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.