设为首页 加入收藏

TOP

Leetcode 高精度 Plus One
2015-07-20 17:48:29 来源: 作者: 【 】 浏览:3
Tags:Leetcode 高精度 Plus One

?

?

Plus One

Total Accepted: 17614 Total Submissions: 55852My Submissions

?

Given a non-negative number represented as an array of digits, plus one to the number.

The digits are stored such that the most significant digit is at the head of the list.


?

题意:给定一个由数组表示大整数,数组的每一个元素对应该数的十进制表示的每一位,对该数进行加 1 操作
思路:高精度加法
复杂度:时间:O(n)

?

vector
  
    plusOne(vector
   
     &digits){ int carry = 1; for(auto it = digits.rbegin(); it != digits.rend(); ++it){ int tmp = *it + carry; *it = tmp % 10; carry = tmp / 10; if(!carry) break; } if(carry) digits.insert(digits.begin(), carry); return digits; }
   
  


?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UVA 10941 - Words adjustment(BF.. 下一篇Leetcode 动态规划 Candy

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何利用Python做数 (2025-12-24 23:48:36)
·如何使用python进行 (2025-12-24 23:48:34)
·python 爬虫入门该怎 (2025-12-24 23:48:31)
·Java 实现多个大文件 (2025-12-24 23:22:00)
·Java多线程编程在工 (2025-12-24 23:21:56)