"Leetcode from zero single row" No67.addbinary

Source: Internet
Author: User

Topics

Given binary strings, return their sum (also a binary string).

For example,
A ="11"
b ="1"
Return"100".

Code
public class Solution {public String addbinary (string A, string b) {string lon= a.length ()-b.length () ; =0?     A:B; String sho= a.length ()-b.length () <0?     A:B;     Char[] Lon_char=lon.tochararray ();     Char[] Sho_char=sho.tochararray ();     Char temp= ' 0 ';     int Final_length=lon.length ()-1;     int index=0;     String[] str=new string[lon.length () +1];     String addbinary_str= "";          for (int i=0;i<sho.length (); i++) {String temp_s=string.valueof (temp);          String sho_char_s=string.valueof (Sho_char[sho.length () -1-i]);          String lon_char_s=string.valueof (Lon_char[lon.length () -1-i]);              Switch (Integer.parseint (temp_s) +integer.parseint (sho_char_s) +integer.parseint (lon_char_s)) {case 0:              temp= ' 0 ';              str[index++]= "0";            Break              Case 1:temp= ' 0 ';              str[index++]= "1";            Break                Case 2:temp= ' 1 ';   str[index++]= "0";             Break                Case 3:temp= ' 1 ';                str[index++]= "1";          Break          }} while (Index<lon.length ()) {String temp_s=string.valueof (temp);                    String lon_char_s=string.valueof (Lon_char[lon.length ()-index-1]);              Switch (Integer.parseint (temp_s) +integer.parseint (lon_char_s)) {case 0:temp= ' 0 ';              str[index++]= "0";            Break              Case 1:temp= ' 0 ';              str[index++]= "1";            Break                Case 2:temp= ' 1 ';                str[index++]= "0";          Break         }} if (temp== ' 1 ') {str[lon.length ()]= "1";     Final_length=lon.length ();     } for (int k=final_length;k>=0;k--) {addbinary_str+=str[k];    } return ADDBINARY_STR; }    }
code Download: Https://github.com/jimenbian/GarvinLeetCode


/********************************

* This article from the blog "Bo Li Garvin"

* Reprint Please indicate the source : Http://blog.csdn.net/buptgshengod

******************************************/



"Leetcode from zero single row" No67.addbinary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.