Advertisement
Guest User

Untitled

a guest
May 26th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public class testerei {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. System.out.println(recStr("acbxdyfjzdmk"));
  6.  
  7. }
  8.  
  9. private static String recStr(String s){
  10. if(s.length() <= 0)
  11. return "";
  12.  
  13. int maxval = s.charAt(0);
  14.  
  15. int nextSubstringMaxval = -1;
  16. String nextSubstring = recStr(s.substring(1));
  17. if(nextSubstring.length() > 0)
  18. nextSubstringMaxval = nextSubstring.charAt(0);
  19.  
  20.  
  21. if(maxval > nextSubstringMaxval)
  22. return (char)maxval+s.replace(""+maxval, "");
  23. else
  24. return (char)nextSubstringMaxval+s.replace(""+nextSubstringMaxval, "");
  25.  
  26.  
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement