-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp.java
More file actions
32 lines (29 loc) · 789 Bytes
/
exp.java
File metadata and controls
32 lines (29 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
public class exp {
public static void main(String[] args) {
orderlyQueue("cba",1);
}
public static String orderlyQueue(String s, int k) {
if(k>1){
char[] arr=s.toCharArray();
Arrays.sort(arr);
String res=new String(arr);
return res;
}
else{
String res2=s;
StringBuilder res=new StringBuilder(s);
int i=0;
while(i<s.length()){
char x=res.charAt(0);
res.deleteCharAt(0);
res.append(x);
if((res.toString()).compareTo(res2)<0) {
res2=res.toString();
}
i++;
}
return res2;
}
}
}