我尝试运行它,但是它非常慢。需要一段时间才能处理并完成计算。无论如何,我是否可以改进它或使其更快,更有效地工作?
int n = 25;
int len = (int) Math.pow(2, n);
String[][] BinaryNumbers = new String[len][];
int[] DummyArray = new int[n];
int[][] BinaryNumbersInt = new int[len][];
for (int count = 0; count < len; count++) {
BinaryNumbers[count] = String.format("%" + n + "s",
Integer.toBinaryString(count)).replace((" "), ("0"))
.split("");
for (int i = 0; i < n; i++) {
DummyArray[i] = Integer.parseInt(BinaryNumbers[count][i]);
}
BinaryNumbersInt[count] = Arrays.copyOf(DummyArray, DummyArray.length);
}
谢谢!
答案 0 :(得分:0)
您正在做很多无用的字符串操作。尝试这样的事情:
for (int count = 0; count < len; count++) {
int[] DummyArray = new int[n];
int x = count;
for (int i = 0; i < n; i++) {
DummyArray[n-i-1] = x & 1;
x >>= 1;
}
BinaryNumbersInt[count] = DummyArray;
}