Skip to content

Commit 5be9432

Browse files
committed
Added comments
1 parent 0668e5d commit 5be9432

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/com/hackerrank/contests/SwappingInAnArray.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
* @since 04/11/2018
1111
*/
1212
public class SwappingInAnArray {
13-
// Complete the swapToSort function below.
13+
14+
/**
15+
* The problem asks if we can sort the array with only one swap.
16+
*
17+
* @param a array to sort
18+
* @return 0 if already sorted, 1 if it can be sorted with one swap, -1 otherwise
19+
*/
1420
static int swapToSort(int[] a) {
15-
// Return -1 or 0 or 1 as described in the problem statement.
1621
int swaps = 0;
1722
for (int i=0; i < a.length-1; i++) {
1823
int swapIndex = i;

0 commit comments

Comments
 (0)