Add Binary字符数字相加,字符串合成
class Solution {
public:
string addBinary(string a, string b) {
string longer=a.length()>b.length() ? a:b;
string shorter=a.length()>b.length() ? b:a;
int add=;
int j=longer.length()-;
for(int i=shorter.length()-;i>=;--i,--j){
if(shorter[i]-''+longer[j]-''+add>){
longer[j]=''+(shorter[i]-''+longer[j]-''+add)%;
add=;
}else{
longer[j]=''+(shorter[i]-''+longer[j]-''+add)%;
add=;
}
}
while(j>=){
if(longer[j]-''+add>){
longer[j]='';
add=;
}else{
longer[j]=longer[j]+add;
add=;
}
--j;
}
if(add)
longer.insert(,,'');
return longer;
}
};
Add Binary字符数字相加,字符串合成的更多相关文章
- LeetCode OJ:Add Digits(数字相加)
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...
- LeetCode OJ:Add Binary(二进制相加)
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...
- LeetCode 258 Add Digits(数字相加,数字根)
翻译 给定一个非负整型数字,反复相加其全部的数字直到最后的结果仅仅有一位数. 比如: 给定sum = 38,这个过程就像是:3 + 8 = 11.1 + 1 = 2.由于2仅仅有一位数.所以返回它. ...
- LeetCode 67 Add Binary(二进制相加)(*)
翻译 给定两个二进制字符串,返回它们的和(也是二进制字符串). 比如, a = "11" b = "1" 返回 "100". 原文 Give ...
- LeetCode 67. Add Binary (二进制相加)
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...
- 如何在Go中获得 "A1","B2" 类似字符+数字的字符串
package main import ( "fmt" ) func main() { // 字符串 str := "ABCDEFGHIJKLMNOPQRSTUVWXYZ ...
- [LeetCode] Add Two Numbers 两个数字相加
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- 对字符串进行简单的字符数字统计 探索java中的List功能
题目: 统计一个字符串中数字和字符串的个数,并分别进行排列,要求 1.数字,字符串可以从键盘获取. 2.储存在list 3.统计数字个数,字符串个数 4.把数字和字符串按从小到大的顺序输出 5.不能使 ...
- [LeetCode] 2. Add Two Numbers 两个数字相加
You are given two non-empty linked lists representing two non-negative integers. The digits are stor ...
随机推荐
- [code]彩色图像直方图均衡化 histogram_rgb
//2013.9 eageldiao #ifdef HISTOGRAM_RGB unsigned ]; unsigned intncount[]={},ncount1[]={},ncount2[]={ ...
- 利用TensorFlow识别手写的数字---基于Softmax回归
1 MNIST数据集 MNIST数据集主要由一些手写数字的图片和相应的标签组成,图片一共有10类,分别对应从0-9,共10个阿拉伯数字.原始的MNIST数据库一共包含下面4个文件,见下表. 训练图像一 ...
- 2019.10.25 csp-s模拟测试87 反思总结
一次非常神奇的考试,考完试以后看着T2的0pts突然笑死我自己 太智障了这什么神奇的题意理解错误23333 T1一眼分类讨论,两眼二分,觉得分类讨论有点玄学但是出题人八成不会卡[何],然后本着对二分的 ...
- 粗浅看 Tomcat系统架构分析
原文出处: 吴士龙 http://www.importnew.com/21112.html Tomcat的结构很复杂,但是Tomcat也非常的模块化,找到了Tomcat最核心的模块,就抓住了Tomca ...
- html 输入框显示“小叉叉”的清空方法
在IE10以下,我们的输入框input会出现小叉叉.怎么解决这个问题呢? 针对input框我们做一个处理 <style type="text/css"> input:: ...
- Eclipse:Eclipse插件开发全套教程
分享是美德,作者为Eclipse核心工程师之一,全英文版,有不明白的地方欢迎探讨和咨询. http://www.vogella.com/tutorials/eclipse.html
- bzoj 3231 [Sdoi2008]递归数列——矩阵乘法
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3231 矩阵乘法裸题. 1018是10^18.别忘了开long long. #include& ...
- cmd下带参数执行python文件
在一个文件下下创建程序代码, sys.argv 即后续cmd中需要传入的参数列表, sys.argv[0]即要执行的文件名 sys.argv[n]即参数的字符串 # -*- c ...
- java窗体swing使用jlabel显示图片
Icon icon = new ImageIcon("src\\resource\\" + jTFimgName.getText()); jLabColor.setIcon(ico ...
- Cannot allocate memory for the buffer pool
优化了一通,启动不了 直接上日志 innodb_buffer_pool_size”.”key_buffer_size” 的大小设置,适当的调大内存分配,减小,然后保存配置文件,重新尝试启mysql 成 ...