SHARE
TWEET

Untitled

bbescos Jan 28th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     vector<int> plusOne(vector<int>& digits) {
  2.        
  3.         int n = digits.size();
  4.         if (digits[n - 1] != 9) {
  5.             digits[n - 1] += 1;
  6.         }
  7.         else {
  8.             int i = 1;
  9.             while (digits[n - i] == 9) {
  10.                 digits[n - i] = 0;
  11.                 if (n - 1 - i < 0) {
  12.                     digits.insert(digits.begin(), 0);
  13.                     break;
  14.                 }
  15.                 ++i;  
  16.             }
  17.             digits[n - i] += 1;
  18.         }
  19.            
  20.         return digits;
  21.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top