设为首页 加入收藏

TOP

Leetcode 高精度 Plus One
2015-07-20 17:48:29 来源: 作者: 【 】 浏览:2
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

评论

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

·C语言结构体怎么直接 (2025-12-24 17:19:44)
·为什么指针作为c语言 (2025-12-24 17:19:41)
·如何较为深入的理解c (2025-12-24 17:19:38)
·Announcing October (2025-12-24 15:18:16)
·MySQL有什么推荐的学 (2025-12-24 15:18:13)