Advertisement
Guest User

Untitled

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