You are viewing a single comment's thread. Return to all comments →
java solution
public static String biggerIsGreater(String w) { // Write your code here boolean change = false; int indexfirstchangeparam = -1; int indexsecondchangeparam = 0; for (int i = w.length() - 1; i > 0; i--) { for (int j = i - 1; j > indexfirstchangeparam ; j--) { if (w.charAt(i) > w.charAt(j)) { change = true; indexfirstchangeparam =j; indexsecondchangeparam = i; break; } } } if (change) { w = w.substring(0, indexfirstchangeparam) + w.charAt(indexsecondchangeparam) + w.substring(indexfirstchangeparam+1,indexsecondchangeparam) + w.charAt(indexfirstchangeparam) + w.substring(indexsecondchangeparam+1,w.length()); for (int k = indexfirstchangeparam + 1; k < w.length(); k++) { int indexmin = k; for (int h = k ; h < w.length(); h++) { if (w.charAt(h) < w.charAt(indexmin)) { indexmin = h; } } if (indexmin > k){ w = w.substring(0, k) + w.charAt(indexmin) + w.substring(k+1,indexmin) + w.charAt(k) + w.substring(indexmin+1,w.length()); } } } if (change) { return w; } else { return "no answer"; } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Bigger is Greater
You are viewing a single comment's thread. Return to all comments →
java solution