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

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

简单的二进制高精度加法。

class Solution {
public:
string addBinary(string a, string b) {
string ans="";
int c=,i=a.length()-,j=b.length()-;
while(i>=||j>=||c>)
{
c+= i>=? a[i--]-'':;
c+= j>=? b[j--]-'':;
ans=char(c%+'') + ans;
c/=;
}
return ans;
}
};

leetcode 67. Add Binary (高精度加法)的更多相关文章

  1. leetCode 67.Add Binary (二进制加法) 解题思路和方法

    Given two binary strings, return their sum (also a binary string). For example, a = "11" b ...

  2. Leetcode 67 Add Binary 大数加法+字符串处理

    题意:两个二进制数相加,大数加法的变形 大数加法流程: 1.倒置两个大数,这一步能使所有大数对齐 2.逐位相加,同时进位 3.倒置两个大数的和作为输出 class Solution { public: ...

  3. [leetcode]67. Add Binary 二进制加法

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

  4. (String) leetcode 67. Add Binary

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

  5. LeetCode 67. Add Binary (二进制相加)

    Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...

  6. [LeetCode] 67. Add Binary 二进制数相加

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

  7. LeetCode 67. Add Binary

    Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...

  8. Java [Leetcode 67]Add Binary

    题目描述: Given two binary strings, return their sum (also a binary string). For example,a = "11&qu ...

  9. LeetCode - 67. Add Binary(4ms)

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

随机推荐

  1. C# DataTable 总结

    (1)构造函数 DataTable()   不带参数初始化DataTable 类的新实例. DataTable(string tableName)  用指定的表名初始化DataTable 类的新实例. ...

  2. c语言中结构体指针

    1.指向结构体的指针变量: C 语言中->是一个总体,它是用于指向结构体,如果我们在程序中定义了一个结构体,然后声明一个指针变量指向这个结构体.那么我们要用指针取出结构体中的数据.就要用到指向运 ...

  3. HDU 2255 奔小康赚大钱 KM裸题

    #include <stdio.h> #include <string.h> #define M 310 #define inf 0x3f3f3f3f int n,nx,ny; ...

  4. webStorm 多列编辑

    webStorm可以像Sublime一样使用列编辑,只是区别在于webStorm只可以编辑连续列表. 按住alt键鼠标选择一列,然后输入文字就会编辑多行,这个功能很赞,比较实用(按住ALT键选中之后, ...

  5. oracle 误删数据的回复操作

    update operator t set t.username = (select username from operator  AS OF TIMESTAMP TO_TIMESTAMP('201 ...

  6. CxImage新手教程,图文并茂

    作为一个游戏client程序猿,须要对图像处理有一定的知识. CxImage是C++实现的功能强大的.能处理多种文件格式的图像管理类.它可以简单高速的实现图像的导入.保存.显示和变换. 同一时候又具有 ...

  7. Python学习总结之五 -- 入门函数式编程

    函数式编程 最近对Python的学习有些怠慢,最近的学习态度和学习效率确实很不好,目前这种病况正在好转. 今天,我把之前学过的Python中函数式编程简单总结一下,分享给大家,也欢迎并感谢大家提出意见 ...

  8. 统计分析表的存储过程遇ORA-00600错误分析与处理

    1.            统计分析表的存储过程部分内容 CREATE OR REPLACE procedure SEA.sp_analyze_XXX_a is v_sql_1     varchar ...

  9. HttpClient 访问 https 出现peer can't

    package util; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext;import ...

  10. 马尔科夫链在第n步转移的状态的概率分布