Remington
BAN USER
Comments (2)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
private static char[] high(int num){
char[] ch = Integer.toString(num).toCharArray();
int point = ch.length-1;
String sRev = "";
Boolean isSwapped = false;
//Find the pivot point as well as store the asc order number
for(;point >0 && ch[point]<ch[point-1];point--)
sRev = sRev + ch[point];
sRev = sRev + ch[point];
char[] rev = sRev.toCharArray();
point--;
//swap the pivot number with next higher number as well as place asc ordered numbers
for(int i=0;i<rev.length;i++){
char tmp = rev[i];
if(!isSwapped && ch[point]<rev[i]){
tmp = ch[point];
ch[point] = rev[i];
isSwapped = true;
}
ch[point+i+1] = tmp;
}
return ch;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Is there any algo to solve this
- Remington June 08, 2012