【leetcode】67-AddBinary
problem
code
class Solution {
public:
string addBinary(string a, string b) {
string res;
int i = a.size()-;
int j = b.size()-;
int carry = ;
while(carry || i >= || j>=)//
{
carry += (i>=) ? a[i--]-'' : ;//
carry += (j>=) ? b[j--]-'' : ;
res = char(carry% + '') + res;//??
carry /= ;
}
return res;
}
};
注意
1.每个字符串中的每个字符对应的数字进行数字运算,且最后的结果是字符串;
2.int型和字符类型之间的转换;
3.string类型可以直接使用符号'+'进行字符串的连接;
4.进位和余数的运算;
参考
完
【leetcode】67-AddBinary的更多相关文章
- 【LeetCode】67. Add Binary 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BigInteger类 模拟加法 日期 题目地址:h ...
- 【LeetCode】67. Add Binary
题目: Given two binary strings, return their sum (also a binary string). For example,a = "11" ...
- 【LEETCODE】67、分治递归,medium&hard级别,题目:215、312
我被这些题整哭了,你呢??? 日了狗啊...... 好难啊.... 按照这个样子搞,不用找工作了,回家放牛去....... package y2019.Algorithm.divideandconqu ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
- 【刷题】【LeetCode】007-整数反转-easy
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
- 【刷题】【LeetCode】000-十大经典排序算法
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法
- 【leetcode】893. Groups of Special-Equivalent Strings
Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...
随机推荐
- MapReduce(一)
MapReduce(一) 一.介绍 百度百科: MapReduce是一种编程模型,用于大规模数据集(大于1TB)的并行运算.概念"Map(映射)"和"Reduce(归约) ...
- iOS block 机制
本文要将block的以下机制,并配合具体代码详细描述: block 与 外部变量 block 的存储域:栈块.堆块.全局块 定义 块与函数类似,只不过是直接定义在另一个函数里,和定义它的那个函数共享同 ...
- FTP服务器搭建(Centos7)
1.1.1 查看是否安装vsftp rpm -qa | grep vsftpd 1.1.2 如果没有安装: yum -y install vsftpd 1.2.3 vsftpd.conf 配置文件 匿 ...
- 【转】vuex2.0 之 modules
vue 使用的是单一状态树对整个应用的状态进行管理,也就是说,应用中的所有状态都放到store中,如果是一个大型应用,状态非常多, store 就会非常庞大,不太好管理.这时vuex 提供了另外一种方 ...
- id: cannot find name for user ID xxx处理办法
一.现像 root用户登录显示正常但以普通用户登录时报类似如下错误: id: cannot find name for user ID 500id: cannot find name for grou ...
- python QMainWindow QWidget
from PyQt5 import QtWidgetsfrom untitled import Ui_MainWindowfrom PyQt5.QtWidgets import QFileDialog ...
- ubuntu 调节音量命令 声卡驱动
alsamixer 安装驱动http://www.realtek.com/downloads/downloadsCheck.aspx?Langid=1&PNid=24&PFid=24& ...
- 神奇的口袋(dp)
有一个神奇的口袋,总的容积是40,用这个口袋可以变出一 些物品,这些物品的总体积必须是40. John现在有n(1≤n ≤ 20)个想要得到的物品,每个物品 的体积分别是a1,a2……an.John可 ...
- 线性回归之决定系数(coefficient of determination)
1. Sum Of Squares Due To Error 对于第i个观察点, 真实数据的Yi与估算出来的Yi-head的之间的差称为第i个residual, SSE 就是所有观察点的residua ...
- QuickStart系列:docker部署之MariaDB
Centos7里面没有Mysql 取而代之的是MariaDB,MariaDB是完全开源的.MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的 ...