You are viewing a single comment's thread. Return to all comments →
static String biggerIsGreater(String w) { char[] arr = w.toCharArray(); int i = arr.length - 1; // finding p --> i while(i>0 && arr[i-1]>=arr[i]){ i--; } if(i<=0){ //System.out.println("Pretty much last one!!"); return "no answer"; } int j = arr.length-1; while(arr[j]<= arr[i-1]){ j--; } char temp = arr[i-1]; arr[i-1] = arr[j]; arr[j] = temp;
j = arr.length - 1; while(i<j) { char tem = arr[i]; arr[i] = arr[j]; arr[j] = tem; j--; i++; } String ret = new String(arr); return ret; }
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 →
Simple java solution : algorithm n wikipedia