标签:整数 字符串 处理 etc 分享 .com images rar img
Given two non-negative integers num1
and num2
represented as string, return the sum of num1
and num2
.
Note:
num1
and num2
is < 5100.num1
and num2
contains only digits 0-9
.num1
and num2
does not contain any leading zero.思路:由于一个字符与一个非负整数等价,所以直接对两个字符串对应字符进行加法运算。诸多细节:首先是向一个string对象指定位置插入字符;然后,为了避免后续处理的麻烦,我直接将两个字符串归一化成一样的长度,用0来补齐;0的ascii为48,在进行字符加法时要十分注意加减48的处理。
标签:整数 字符串 处理 etc 分享 .com images rar img
原文地址:http://www.cnblogs.com/vincent93/p/6686627.html