Skip to content

Refactored Identifiers #5306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/thealgorithms/misc/TwoSumProblem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ private TwoSumProblem() {
public static Optional<Pair<Integer, Integer>> twoSum(final int[] values, final int target) {
HashMap<Integer, Integer> valueToIndex = new HashMap<>();
for (int i = 0; i < values.length; i++) {
final var rem = target - values[i];
if (valueToIndex.containsKey(rem)) {
return Optional.of(Pair.of(valueToIndex.get(rem), i));
final var remainder = target - values[i];
if (valueToIndex.containsKey(remainder)) {
return Optional.of(Pair.of(valueToIndex.get(remainder), i));
}
if (!valueToIndex.containsKey(values[i])) {
valueToIndex.put(values[i], i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public static void main(String[] args) {
Integer[] integers = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};

int size = integers.length;
Integer shouldBeFound = 128;
Integer targetValue = 128;
FibonacciSearch fsearch = new FibonacciSearch();
int atIndex = fsearch.find(integers, shouldBeFound);
int atIndex = fsearch.find(integers, targetValue);

System.out.println("Should be found: " + shouldBeFound + ". Found " + integers[atIndex] + " at index " + atIndex + ". An array length " + size);
System.out.println("Should be found: " + targetValue + ". Found " + integers[atIndex] + " at index " + atIndex + ". An array length " + size);
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/thealgorithms/strings/WordLadder.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public static int ladderLength(String beginWord, String endWord, List<String> wo
continue;
}
wordsChars[j] = c;
String newWord = String.valueOf(wordsChars);
if (newWord.equals(endWord)) {
String transformedWord = String.valueOf(wordsChars);
if (transformedWord.equals(endWord)) {
return level + 1;
}
if (set.contains(newWord)) {
set.remove(newWord);
queue.offer(newWord);
if (set.contains(transformedWord)) {
set.remove(transformedWord);
queue.offer(transformedWord);
}
}
wordsChars[j] = originalChars;
Expand Down