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. CSS3 background属性

    background: #00FF00 url(bgimage.gif) no-repeat fixed top; background 简写属性在一个声明中设置所有的背景属性. 可以设置如下属性: ...

  2. JAVA学习第二十五课(多线程(四))- 单例设计模式涉及的多线程问题

    一.多线程下的单例设计模式 利用双重推断的形式解决懒汉式的安全问题和效率问题 //饿汉式 /*class Single { private static final Single t = new Si ...

  3. 【PyCharm编辑器】之报:Spellchecker inspection helps locate typos and misspelling in your code, comments and literals, and fix them in one click.问题

    如上图,输入一个单词时会出现波浪线,报:Spellchecker inspection helps locate typos and misspelling in your code, comment ...

  4. 深入Asyncio(九)异步生成器

    Async Generators:yield inside async def functions 如果在async def中使用yield会发生什么,答案就是生成一个异步生成器函数,如果有生成器.协 ...

  5. linux环境tomcat配置及hadoop 2.6伪分布模式安装配置

    一.ubuntu 15.04.openjdk1.7.tomcat7环境配置 1. 配置openjdk1.7,输入命令: -jdk 2. 查看java是否安装成功,输入命令: envjava -vers ...

  6. Android-自定义广播不能用的可能的原因(sendbroadcast 不起效果)

    参考博客:https://blog.csdn.net/chuyouyinghe/article/details/79424373 照着书上的源码将程序原封不动敲了一遍,但发现这特么怎么也收不到发出的广 ...

  7. Android UI开发第四十三篇——使用Property Animation实现墨迹天气3.0引导界面及动画实现

    前面写过<墨迹天气3.0引导界面及动画实现>,里面完美实现了动画效果,那一篇文章使用的View Animation,这一篇文章使用的Property Animation实现.Propert ...

  8. mongodb.py

    from chatterbot.storage import StorageAdapter class Query(object): def __init__(self, query={}): sel ...

  9. 九度OJ 1065:输出梯形 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5379 解决:2939 题目描述: 输入一个高度h,输出一个高为h,上底边为h的梯形. 输入: 一个整数h(1<=h<=1000 ...

  10. JAVA中int与String类型的相互转换

    Java的int和String类型间互相转换,小功能但是经常用到,下面是几种实现的方法: 字符串类型String转换成整数int 1. int i = Integer.parseInt([String ...