LeetCode-Solutions icon indicating copy to clipboard operation
LeetCode-Solutions copied to clipboard

Add plus one java

Open helloitsxinyi opened this issue 4 years ago • 1 comments

Question: You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's.

Increment the large integer by one and return the resulting array of digits.

Approach: if number does not consist of only 9s, increment the last digit in the array by 1. If number consists of only 9s, reassign all the digits to be 0. Create a new array that is larger by 1 (with all digits as 0 by default). Set the first digit as 1.

Put check marks:

Have you made changes in README file ?

  • [x] Added problem & solution under correct topic.
  • [x] Specified Space & Time complexity.
  • [x] Specified difficulty level, tag & Note(if any).

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also note any relevant details for your test configuration.

  • [x] Test on Leetcode, accepted

Make sure all below guidelines are followed else PR will get Reject:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] I have commented my code so that it is easy to understand
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] Any dependent changes have been merged and published in downstream modules

helloitsxinyi avatar Oct 29 '21 13:10 helloitsxinyi

I can tell this is your first pull request! Thank you I'm so honored. :tada::tada::tada: I'll take a look at it ASAP!

welcome[bot] avatar Oct 29 '21 13:10 welcome[bot]