【LeetCode 67_字符串_算术运算】Add Binary

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的更多相关文章
- 【LeetCode 38_字符串_算术运算】Count and Say
string countAndSay(int n) { string res; ) return res; res = "; ) { int len = res.size(); int i, ...
- 【LeetCode每天一题】Add Binary(二进制加法)
Given two binary strings, return their sum (also a binary string).The input strings are both non-emp ...
- 【Leetcode】【Easy】Add Binary
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...
- 【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. ...
- 【LeetCode 8_字符串_实现】String to Integer (atoi)
, INVALID}; int g_status; long long SubStrToInt(const char* str, bool minus) { ; : ; while (*str != ...
- 【leetcode刷题笔记】Add Binary
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...
- 【LeetCode 144_二叉树_遍历】Binary Tree Preorder Traversal
解法一:非递归 vector<int> preorderTraversal(TreeNode* root) { vector<int> res; if (root == NUL ...
- 【LeetCode 28_字符串_匹配】Implement strStr()
解法一:Brute-force int strStr(string haystack, string needle) { int m = haystack.size(); int n = needle ...
- [LeetCode] 415 Add Strings && 67 Add Binary && 43 Multiply Strings
这些题目是高精度加法和高精度乘法相关的,复习了一下就做了,没想到难住自己的是C++里面string的用法. 原题地址: 415 Add Strings:https://leetcode.com/pro ...
随机推荐
- HBuilder android 打包指南(V客学院技术分享)
前提:确保配置文件(manifest.json)已配置完,没有异常. 打包选项如下: Android 包名 :在Android系统中是判断一个App的唯一标识,不同的App可以有同样的名字,但是它的包 ...
- tomcat+svn+maven+jenkins实现自动构建
首先说明一个各软件的版本: tomcat:apache-tomcat-8.5.16.tar.gz maven:apache-maven-3.5.0-bin.tar.gz svn:subversion- ...
- 201453131《Java程序设计》实验三实验报告
实验三 敏捷开发与XP实践 实验内容 •下载并学会使用git上传代码: •与同学结对,相互下载并更改对方代码,并上传: 实验步骤 下载并用git上传代码: •1.下载并安装好git,在cmd中输入gi ...
- linux消息队列应用编程
消息队列: 消息队列提供了一个从一个进程向另外一个进程发送一块数据的方法 每个数据块都被认为是有一个类型,接收者进程接收的数据块可以有不同的类型值 消息队列也有管道一样的不足,就是每个消息的 ...
- SVN添加忽略目录
项目:Thinkphp 目录结构: Thinkphp |-- Common |-- Runtime |-- Home 忽略目标: Runtime 文件夹及下面所有文件 首先,需要忽略的目录必须没有加入 ...
- uboot源码中"include/configs/$(boardname).h"与"configs/$(boardname)_defconfig"之间有何异同
答:最大的不同就是"configs/boardname_defconfig"中的选项都可以在make menuconfig中进行配置,而"include/configs/ ...
- 关于JBoss的一些项目配置
1. 如何使用 IP:port 的形式访问项目 : [1] 在standalone.xml文件中,查找<interfaces>标签,添加如下节点 : <interface name= ...
- 编译libmemcached
php的扩展memcache,不支持cas,所以我们要装memcached扩展,memcached扩展是基于libmemcached,所以要先安装libmemcached 一.下载软件 1.libme ...
- Android开发—Volley 的使用
1.下载 Volley .当然首先得FQ,本人FQ用的是 SSH 代理,客户端使用 Shadowsocks ,连的服务器是博士提供的***服务.然后再打开 Git Bash 设置代理并下载 Volle ...
- AtCoder Grand Round 012B Splatter Painting
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...