Skip to content

Instantly share code, notes, and snippets.

@vijayparashar12
Last active March 14, 2019 20:56
Show Gist options
  • Save vijayparashar12/48f3608cd33becedc39d8b91c5208286 to your computer and use it in GitHub Desktop.
Save vijayparashar12/48f3608cd33becedc39d8b91c5208286 to your computer and use it in GitHub Desktop.
Find the smallest number to given Integer with same number of digits: smallestNumber(125) = 100 , smallestNumber(10) = 10
public class Solution {
public static int smallestNumber(int num) {
int count = 0;
while (num > 0) {
num = num / 10;
count++;
}
return (int) Math.pow(10, count - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment