zoukankan      html  css  js  c++  java
  • LeetCode--Plus One

    考查,最高位有进位

     1 class Solution {
     2 public:
     3     vector<int> plusOne(vector<int> &digits) {
     4         // IMPORTANT: Please reset any member data you declared, as
     5         // the same Solution instance will be reused for each test case.
     6         int i;
     7         int n=digits.size();
     8         if(n==0)
     9             return digits;
    10         int mod=1;
    11         for(i=n-1;i>=0;--i)
    12         {
    13             digits[i]+=mod;
    14             mod=digits[i]/10;
    15             digits[i]=digits[i]%10;
    16             
    17         }
    18         if(mod!=0)
    19             digits.insert(digits.begin(),mod);
    20         return digits;
    21     }
    22 };
  • 相关阅读:
    Day6
    Day6
    Day6
    Day6
    Day6
    Day6
    LeetCode "The Skyline Problem"
    HackerRank
    HackerRank
    HackerRank
  • 原文地址:https://www.cnblogs.com/cane/p/3957005.html
Copyright © 2011-2022 走看看