string addBinary(string a, string b)
{
int alen = a.size();
int blen = b.size();
if (alen == )
return b;
else if (blen == )
return a; int i = alen - ;
int j = blen - ;
int carry = ;
string res;
while (i >= || j >= || carry > ) {
if (i >= )
carry += a[i--] - '';
if (j >= )
carry += b[j--] - '';
res = (char)(carry % + '') + res; //res不用逆序处理了
carry = carry / ;
}
return res;
}

【LeetCode 67_字符串_算术运算】Add Binary的更多相关文章

  1. 【LeetCode 38_字符串_算术运算】Count and Say

    string countAndSay(int n) { string res; ) return res; res = "; ) { int len = res.size(); int i, ...

  2. 【LeetCode每天一题】Add Binary(二进制加法)

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

  3. 【Leetcode】【Easy】Add Binary

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

  4. 【LeetCode】66 & 67- Plus One & Add Binary

    66 - Plus One Given a non-negative number represented as an array of digits, plus one to the number. ...

  5. 【LeetCode 8_字符串_实现】String to Integer (atoi)

    , INVALID}; int g_status; long long SubStrToInt(const char* str, bool minus) { ; : ; while (*str != ...

  6. 【leetcode刷题笔记】Add Binary

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

  7. 【LeetCode 144_二叉树_遍历】Binary Tree Preorder Traversal

    解法一:非递归 vector<int> preorderTraversal(TreeNode* root) { vector<int> res; if (root == NUL ...

  8. 【LeetCode 28_字符串_匹配】Implement strStr()

    解法一:Brute-force int strStr(string haystack, string needle) { int m = haystack.size(); int n = needle ...

  9. [LeetCode] 415 Add Strings && 67 Add Binary && 43 Multiply Strings

    这些题目是高精度加法和高精度乘法相关的,复习了一下就做了,没想到难住自己的是C++里面string的用法. 原题地址: 415 Add Strings:https://leetcode.com/pro ...

随机推荐

  1. iis日志时间与本地日期不一样

    iis日志里面的时间是 UTC时间,所以要自已加时区进行转换:即 utc时间+8小时:

  2. eclipse web项目的发布路径

    java Build path是编译路径设置,主要用来设置源代码的编译路径默认是default output folder Web Deployment Assembly是eclipse中的发布路径设 ...

  3. MVC readioButtonList的创作过程及运用

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Li ...

  4. mouseleave mouseout时候悬浮框不应该消失的时候消失了 css 解决办法

    要实现的效果和代码思路 简单来说就是 用一个div包着喇叭和悬浮框 悬浮事件写在这个div上 鼠标悬浮到div上的时候 悬浮框出现 最终要做成鼠标从小喇叭移动到下面的框上的时候 下面框是不会消失的. ...

  5. MySQL多版本并发控制机制(MVCC)-源码浅析

    MySQL多版本并发控制机制(MVCC)-源码浅析 前言 作为一个数据库爱好者,自己动手写过简单的SQL解析器以及存储引擎,但感觉还是不够过瘾.<<事务处理-概念与技术>>诚然 ...

  6. python windows打包

    接触过的工具有pyinstaller,或者py2exe.感觉pyinstaller更简单易用. 真正将依赖的dll打包称一个安装包还需要借助windows打包工具 Inno Setup 或 NSIS ...

  7. 关于JavaScript对象,你所不知道的事(二)- 再说属性

    说完了对象那些不常用的冷知识,是时候来看看JavaScript中对象属性有哪些有意思的东西了. 不出你所料,对象属性自然也有其相应的特征属性,但是这个话题有点复杂,让我们先从简单的说起,对象属性的分类 ...

  8. [转载]Javassist 使用指南(一)

    ======================= 本文转载自简书,感谢原作者!. 原链接如下:https://www.jianshu.com/p/43424242846b =============== ...

  9. Flutter中集成Font Awesome

    1.添加引用 在 pubspec.yaml文件中,加入 font awesome的引用 dependencies: flutter: sdk: flutter # The following adds ...

  10. [BZOJ4756]Promotion Counting

    Description The cows have once again tried to form a startup company, failing to remember from past ...