@@ -44,26 +44,10 @@ private PermuteString() {
44
44
*/
45
45
public static Set <String > getPermutations (String str ) {
46
46
Set <String > permutations = new HashSet <>();
47
- PermuteString . generatePermutations (str , 0 , str .length (), permutations );
47
+ generatePermutations (str , 0 , str .length (), permutations );
48
48
return permutations ;
49
49
}
50
50
51
- /**
52
- * Swaps the characters at the specified positions in the given string.
53
- *
54
- * @param str the string in which characters will be swapped
55
- * @param i the position of the first character to swap
56
- * @param j the position of the second character to swap
57
- * @return a new string with the characters at positions i and j swapped
58
- */
59
- private static String swapCharacters (String str , int i , int j ) {
60
- char [] chars = str .toCharArray ();
61
- char temp = chars [i ];
62
- chars [i ] = chars [j ];
63
- chars [j ] = temp ;
64
- return new String (chars );
65
- }
66
-
67
51
/**
68
52
* Generates all permutations of the given string and collects them into a set.
69
53
*
@@ -86,4 +70,20 @@ private static void generatePermutations(String str, int start, int end, Set<Str
86
70
}
87
71
}
88
72
}
73
+
74
+ /**
75
+ * Swaps the characters at the specified positions in the given string.
76
+ *
77
+ * @param str the string in which characters will be swapped
78
+ * @param i the position of the first character to swap
79
+ * @param j the position of the second character to swap
80
+ * @return a new string with the characters at positions i and j swapped
81
+ */
82
+ private static String swapCharacters (String str , int i , int j ) {
83
+ char [] chars = str .toCharArray ();
84
+ char temp = chars [i ];
85
+ chars [i ] = chars [j ];
86
+ chars [j ] = temp ;
87
+ return new String (chars );
88
+ }
89
89
}
0 commit comments