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.
import java.math.BigInteger;
public class Solution {
public int[] plusOne(int[] digits) {
String str = "";
String[] strs = new String[digits.length];
for(int i=0;i<digits.length;i++){
strs[i] = String.valueOf(digits[i]);
}
for(int i=0;i<digits.length;i++){
str = str + strs[i];
}
BigInteger bigNumber = new BigInteger("1");
BigInteger bigNumber2 = new BigInteger(str);
BigInteger bigNumber3 = bigNumber.add(bigNumber2);
//System.out.println(str.length());
//int number2 = number + 1;
String str2 = String.valueOf(bigNumber3);
int[] digits2 = new int[str2.length()];
for(int i=0;i<str2.length();i++){
digits2[i] = Integer.parseInt(str2.substring(i, i+1));
}
return digits2;
}
}