1/* 2 * given two strings, determine whether the characters of one of the strings can be changed to another after being rearranged, in fact, that is, the problem of the displacement word 3 * For example, A = 'abc' B = 'acb' can be changed to B through the 4 * idea of a; 5*1. should the analysis be conducted. Are the reserved words case sensitive? For example, is God and dog an immutable word? Do you still need to consider space issues? 6 * Here we assume it is case sensitive. 7*2. when comparing two strings, if their lengths are not equal, it is definitely not an immutator 8*9*10 */11 12 public class issamestring {13 14 public static void main (string [] ARGs) {15 // todo auto-generated method stub16 string S = "ABCD"; 17 string T = "dcba"; 18 issamestring ISS = new issamestring (); 19 Boolean flag = ISS. permutation (S, T); 20 if (FLAG) 21 system. out. println ("displacement"); 22 else23 system. out. println ("not modified words"); 24 25} 26/* 27 * if the two are modified words, they all have the same Characters, but the order is different. If 28 * is used to sort them, returns the same string Order 29 *. You can use this to determine 30*31 */32 Public String sort (string s) 33 {34 char [] content = S. tochararray (); 35 Java. util. arrays. sort (content); 36 return new string (content); 37} 38 public Boolean permutation (string S, string t) 39 {40 if (S. length ()! = T. Length () 41 return false; 42 return sort (s). Equals (sort (t); 43} 44 45 46 47}
Given two strings, determine whether the characters of one of the strings can be changed to another string after being rearranged.