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. suse linux 常用命令

    功能:rm 命令,删除一个目录中的一个或多个文件或目录(文件夹). 它也可以将某个目录及其下的所有文件及子目录均删除. 对于链接文件,只是删除了链接,原有文件均保持不变. 文件一旦被删除,它不能被恢复 ...

  2. WebMagic 爬虫框架

    官方网站[http://webmagic.io/](http://webmagic.io/) >webmagic是一个开源的Java垂直爬虫框架,目标是简化爬虫的开发流程,让开发者专注于逻辑功能 ...

  3. netbeans许可证模板设置

    工具->模板->设置 user=your name 工具->模板->许可证->默认许可证 <#if licenseFirst??>${licenseFirst ...

  4. [转]tomcat之一:指定tomcat运行时JDK版本

    今天在做项目的时候,主管让我在本机上启动多个tomcat且指定不同的jdk环境.因为在企业的项目中个,对于同一个服务器中有多个jdk和tomcat,所以就需要手动指定不同的jdk. 在网上找了很多资料 ...

  5. 机器学习与R语言:NB

    #---------------------------------------- # 功能描述:演示NB建模过程 # 数据集:SMS文本信息 # tm包:维也纳财经大学提供 #----------- ...

  6. Spark高级数据分析· 2数据分析

    wget https://archive.ics.uci.edu/ml/machine-learning-databases/00210/donation.zip 数据清洗 cd /Users/eri ...

  7. NRF24L01——工作原理解读

    源: NRF24L01——工作原理解读

  8. nsis源码 nsisdialogdesigner

    ; 安装程序初始定义常量!define PRODUCT_NAME "nsisdialogdesigner"!define PRODUCT_VERSION "1.1.3&q ...

  9. JAVA启动参数整理[转]

    java启动参数共分为三类: 其一是标准参数(-),所有的JVM实现都必须实现这些参数的功能,而且向后兼容: 其二是非标准参数(-X),默认jvm实现这些参数的功能,但是并不保证所有jvm实现都满足, ...

  10. 【链接】Eclipse的Debug调试技巧

    Eclipse的Debug调试技巧大全 https://mp.weixin.qq.com/s/bORg9YxJiby2WenYRrXY-w 使用Eclipse调试Java程序的10个技巧 https: ...