pull/3/head
左程云 5 years ago
parent 5f1daf88f3
commit d86c49c539

@ -27,10 +27,7 @@ public class Code01_LowestLexicography {
// 已经使用过的字符串的下标在use里登记了不要再使用了 // 已经使用过的字符串的下标在use里登记了不要再使用了
// 之前使用过的字符串,拼接成了-> path // 之前使用过的字符串,拼接成了-> path
// 用all收集所有可能的拼接结果 // 用all收集所有可能的拼接结果
public static void process(String[] strs, public static void process(String[] strs, HashSet<Integer> use, String path, ArrayList<String> all) {
HashSet<Integer> use,
String path,
ArrayList<String> all) {
if (use.size() == strs.length) { if (use.size() == strs.length) {
all.add(path); all.add(path);
} else { } else {
@ -68,7 +65,7 @@ public class Code01_LowestLexicography {
char[] ans = new char[(int) (Math.random() * strLen) + 1]; char[] ans = new char[(int) (Math.random() * strLen) + 1];
for (int i = 0; i < ans.length; i++) { for (int i = 0; i < ans.length; i++) {
int value = (int) (Math.random() * 5); int value = (int) (Math.random() * 5);
ans[i] = (char) (97 + value); ans[i] = (Math.random() <= 0.5) ? (char) (65 + value) : (char) (97 + value);
} }
return String.valueOf(ans); return String.valueOf(ans);
} }
@ -95,10 +92,21 @@ public class Code01_LowestLexicography {
int arrLen = 6; int arrLen = 6;
int strLen = 5; int strLen = 5;
int testTimes = 100000; int testTimes = 100000;
String[] arr = generateRandomStringArray(arrLen, strLen);
System.out.println("先打印一个生成的字符串");
for (String str : arr) {
System.out.print(str + ",");
}
System.out.println();
System.out.println("test begin");
for (int i = 0; i < testTimes; i++) { for (int i = 0; i < testTimes; i++) {
String[] arr1 = generateRandomStringArray(arrLen, strLen); String[] arr1 = generateRandomStringArray(arrLen, strLen);
String[] arr2 = copyStringArray(arr1); String[] arr2 = copyStringArray(arr1);
if (!lowestString1(arr1).equals(lowestString2(arr2))) { if (!lowestString1(arr1).equals(lowestString2(arr2))) {
for (String str : arr1) {
System.out.print(str + ",");
}
System.out.println();
System.out.println("Oops!"); System.out.println("Oops!");
} }
} }

Loading…
Cancel
Save