Skip to content

Commit 1e4e5a2

Browse files
committed
Update Permutation.java
1 parent e00426d commit 1e4e5a2

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/main/java/org/cicirello/permutations/Permutation.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -774,15 +774,11 @@ public void reverse(int i, int j) {
774774
public void removeAndInsert(int i, int j) {
775775
if (i < j) {
776776
int n = permutation[i];
777-
for (int k = i; k < j; k++) {
778-
permutation[k] = permutation[k + 1];
779-
}
777+
System.arraycopy(permutation, i + 1, permutation, i, j - i);
780778
permutation[j] = n;
781779
} else if (i > j) {
782780
int n = permutation[i];
783-
for (int k = i; k > j; k--) {
784-
permutation[k] = permutation[k - 1];
785-
}
781+
System.arraycopy(permutation, j, permutation, j + 1, i - j);
786782
permutation[j] = n;
787783
}
788784
}

0 commit comments

Comments
 (0)