We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Try checking is the next permutated string is actually greater than the original string or not.
Try
if(next_str.equals(str)||next_str.compareTo(str)<1)System.out.println("no answer");
permutated string=next_str
original=string
Now if the permutated string compareTo original string is smaller then print "no answer" because it is actually smaller than the original string.
It happens when pivot=swap=0 means rest of the characters are already smaller.
Bigger is Greater
You are viewing a single comment's thread. Return to all comments →
Try checking is the next permutated string is actually greater than the original string or not. Try if(next_str.equals(str)||next_str.compareTo(str)<1)System.out.println("no answer"); permutated string=next_str original=string Now if the permutated string compareTo original string is smaller then print "no answer" because it is actually smaller than the original string. It happens when pivot=swap=0 means rest of the characters are already smaller.