首页 > 其他 > 详细

36. leetcode 415. Add Strings

时间:2017-04-09 22:09:26      阅读:207      评论:0      收藏:0      [点我收藏+]

415. Add Strings

 

Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.

Note:

  1. The length of both num1 and num2 is < 5100.
  2. Both num1 and num2 contains only digits 0-9.
  3. Both num1 and num2 does not contain any leading zero.
  4. You must not use any built-in BigInteger library or convert the inputs to integer directly.

思路:由于一个字符与一个非负整数等价,所以直接对两个字符串对应字符进行加法运算。诸多细节:首先是向一个string对象指定位置插入字符;然后,为了避免后续处理的麻烦,我直接将两个字符串归一化成一样的长度,用0来补齐;0的ascii为48,在进行字符加法时要十分注意加减48的处理。

技术分享

 

36. leetcode 415. Add Strings

原文:http://www.cnblogs.com/vincent93/p/6686627.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!