diff --git a/Array/Add One To Number b/Array/Add One To Number index 53987e5..701508d 100644 --- a/Array/Add One To Number +++ b/Array/Add One To Number @@ -1,5 +1,5 @@ /* - +Code Available in C++ & Java8 Given a non-negative number represented as an array of digits, add 1 to the number ( increment the number represented by the digits ). @@ -22,7 +22,7 @@ Q : Can the output have 0’s before the most significant digit? Or in other wor A : For the purpose of this question, NO. Even if the input has zeroes before the most significant digit. */ - +//C++ code vector Solution::plusOne(vector &A) { // Do not write main() function. // Do not read input, instead use the arguments to the function. @@ -46,3 +46,79 @@ vector Solution::plusOne(vector &A) { } return res; } + + +// Java 8 code +public class Solution { + public int[] plusOne(int[] A) { + int n= A.length; + if(A[0]==0 && n==1){ + A[0]++; + return A; + } + else if(A[0]==0 && n>1){ + int cnt=0,j=0; + while(A[j]==0){ + cnt++; + j++; + } + int x = n-cnt; + int[] C = new int[x]; + for(int i =0;i