<> Title Description :

Given two binary strings , Back to their and ( In binary form ).
The input is a non empty string and contains only numbers 1 and 0.

<> Examples 1:

input : a = “11”, b = “1”
output : “100”

<> Examples 2:

input : a = “1010”, b = “1011”
output : “10101”

<> Question answer :

<> method 1: Backward Traversal

Record mark bit , Adds the tag bit to the corresponding bit of two strings , Analysis and , Determines the value of the current bit and whether carry is required .
Running time 0ms, The code is as follows .
#define max(a, b) ((a) > (b) ? (a) : (b)) char* addBinary(char* a, char* b) {
if(a == NULL || *a == NULL) return b; if(b == NULL || *b == NULL) return a; int
flag= 0; int len1 = strlen(a), len2 = strlen(b); int len = max(len1, len2) + 2;
char* result = (char*)malloc(len * sizeof(char)); result[len - 1] = '\0'; int i
= 0, j = 0, index = len - 2; while(len1 || len2 || flag) { int t = flag; if(len1
) t += (a[--len1] - '0'); if(len2) t += (b[--len2] - '0'); flag = t / 2; result[
index--] = '0' + t % 2; } if(index == 0) { char* temp = (char*)malloc((len - 1)
* sizeof(char)); memcpy(temp, result + 1, (len - 1) * sizeof(char)); free(result
); return temp; } return result; }

Technology
©2019-2020 Toolsou All rights reserved,
LED Scrolling text ( Essence )2020 year 8 month 9 day C# Basic knowledge reflex Front end to background 5 Summary of different ways [RK3399][Android7.1] Learning notes DRM Driver development ( introduce )( Essence )2020 year 6 month 26 day C# Class library GUID Help class ( Essence 2020 year 6 month 2 Daily update ) TypeScript Function explanation Summary of artificial intelligence algorithm el-ui:select Get value [work] python read txt Last line of file Java Thread of Sleep() Summary of usage