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. Oracle中的substr()函数详解案例

    1)substr函数格式   (俗称:字符截取函数) 格式1: substr(string string, int a, int b); 格式2:substr(string string, int a ...

  2. 创建squashfs

    SquashFS 通常的livecd都有一个这个文件,是核心的文件系统 SquashFS 也是一个只读的文件系统,它可以将整个文件系统压缩在一起,存放在某个设备,某个分区或者普通的文件中.如果您将其压 ...

  3. 20145331 《Java程序设计》第10周学习总结

    20145331 <Java程序设计>第10周学习总结 教材学习内容总结 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置 ...

  4. 快用Visual Studio(五)- 语言特性

    HTML 自带Emment $ SHIFT + OPTION + F:格式化代码 其他语言特性提示 CSS & LESS hover属性,提示样式对象标签 $ CMD + SHIFT + O: ...

  5. TortoiseSVN忽略文件夹

    因为平时要做一些主干.分支的版本控制,发布增量补丁包工作,所以经常使用TortoiseSVN客户端.当然,eclipse中也安装了SVN插件,不过在打补丁方面感觉不如客户端.现在遇到了一个问题:同一项 ...

  6. 感觉Google要搞事情

  7. PayPal2019春招实习生笔试题的某一题

    题目简单描述:给你n个点的坐标(x, y),均为浮点数. 如果任意两个点之间的欧几里得距离小于给定的一个浮点值,则认为这两个点之间有关联,并且关联具有传递性,总之就是尽可能扩大一个集合. 输入: d ...

  8. Commons Configuration之一简介

    转载自(https://my.oschina.net/u/2000201/blog/486327) 1    简介 Commons Configuration软件类库提供通用配置接口,使Java应用程 ...

  9. SSM到Spring Boot-从零开发校园商铺平台

    第1章 开发准备 本章包含课程介绍,同时讲解开发网站所需要准备的事情,并且带领大家从零开始搭建一个Maven Web. 1-1 课程导学 1-2 开发准备 第2章 项目设计和框架搭建 本章主要先带领大 ...

  10. Feign PathVariable annotation was empty on param 0.

    使用Feign的时候,如果参数中带有 @PathVariable形式的参数,则要用value=""标明对应的参数,否则会抛出IllegalStateException异常 如 @P ...