RISHI DUBEY
New member
- Joined
- Sep 27, 2024
- Messages
- 3
- Thread Author
- #1
class Solution {
public int[] plusOne(int[] digits) {
int sum=0;
for(int i=0;i<digits.length;i++)
{
sum=sum*10+digits;
}
sum=sum+1;
int h=sum;
int i=0;
while(sum>0) //count no. of digits
{
sum=sum/10;
i++;
}
digits=new int; // increase size of array as per required
for(int k=digits.length-1;k>=0;k--) //insert element in array
{
digits[k]=h%10;
h=h/10;
}
return digits;
}
}
public int[] plusOne(int[] digits) {
int sum=0;
for(int i=0;i<digits.length;i++)
{
sum=sum*10+digits;
}
sum=sum+1;
int h=sum;
int i=0;
while(sum>0) //count no. of digits
{
sum=sum/10;
i++;
}
digits=new int; // increase size of array as per required
for(int k=digits.length-1;k>=0;k--) //insert element in array
{
digits[k]=h%10;
h=h/10;
}
return digits;
}
}
Last edited: