【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 ...
随机推荐
- 仿netty线程池简化版本
package com.hcxy.car.threadpools; import java.io.IOException; import java.nio.channels.Selector; imp ...
- Mediainfo的编译安装(suse)
Mediainfo 依赖libz和libzen以及libmediainfo,编译顺序为: libz, libzen, libmediainfo (1)编译libz(suse 11已经有了这个库,跳过此 ...
- hive union all使用注意
UNION用于联合多个select语句的结果集,合并为一个独立的结果集,结果集去重. UNION ALL也是用于联合多个select语句的结果集.但是不能消除重复行.现在hive只支持UNION AL ...
- CSS 图片廊
CSS 图片廊 一.示例一 代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- Yahoo网站性能优化的34条规则
摘自:http://blog.chinaunix.net/uid/20714478/cid-74195-list-1.html Yahoo网站性能优化的34条规则 1.尽量减少HTTP请求次数 终端用 ...
- [Linux 001]——计算机和操作系统的基础知识
在正式开始学习 Linux 操作系统之前,有必要先回顾/学习一下计算机和操作系统的基本知识,为我们在后续的学习中铺路搭桥,在了解计算机一些基础原理的条件下再去进行学习,理解应该会更透彻一些.我会从一个 ...
- PostgreSQL 递归查询 (转)
数据库中的数据存在父子关系(单继承,每一条记录只有一个父亲). 如果要查询一条记录以及他的所有子记录,或者要查询一条记录以及他的所有父记录.那么递归查询就再合适不过了.可以简化复杂的SQL语句 现在 ...
- cogs 539. 牛棚的灯
★★☆ 输入文件:lights.in 输出文件:lights.out 简单对比 时间限制:1 s 内存限制:128 MB [问题描述] 贝希和她的闺密们在她们的牛棚中玩游戏.但是天不从 ...
- 【转载】showModalDialog returnValue is undefined in Google Chrome
showModalDialog returnValue is undefined in Google Chrome Posted on August 22, 2012by briancaos For ...
- Hibernate的懒加载session丢失解决方法
在web.xml加入spring提供的过滤器,延长session的生命周期 <!--Hibernate的懒加载session丢失解决方法 --> <filter> <fi ...