Skip to content

Commit

Permalink
6.8. Метод двух указателей; Array traversal check, algorithm accelera…
Browse files Browse the repository at this point in the history
  • Loading branch information
Temzor committed Oct 5, 2023
1 parent 79b79b8 commit e8963a4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/ru/j4j/array/TwoNumberSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ public static int[] getIndexes(int[] array, int target) {
int j = array.length - 1;
while (i < j) {
int sum = array[i] + array[j];
if (i > array.length / 2 || j < array.length / 2) {
break;
}
if (sum == target) {
return new int[]{i, j};
return new int[] {i, j};
} else if (sum < target) {
i++;
} else {
j--;
}
}
return new int[]{};
return new int[] {};
}
}

0 comments on commit e8963a4

Please sign in to comment.