Refactored Identifiers (#5306)
Co-authored-by: Bama Charan Chhandogi <b.c.chhandogi@gmail.com>
This commit is contained in:
parent
6e23e198ab
commit
cafea1ee52
@ -20,9 +20,9 @@ public final class TwoSumProblem {
|
|||||||
public static Optional<Pair<Integer, Integer>> twoSum(final int[] values, final int target) {
|
public static Optional<Pair<Integer, Integer>> twoSum(final int[] values, final int target) {
|
||||||
HashMap<Integer, Integer> valueToIndex = new HashMap<>();
|
HashMap<Integer, Integer> valueToIndex = new HashMap<>();
|
||||||
for (int i = 0; i < values.length; i++) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
final var rem = target - values[i];
|
final var remainder = target - values[i];
|
||||||
if (valueToIndex.containsKey(rem)) {
|
if (valueToIndex.containsKey(remainder)) {
|
||||||
return Optional.of(Pair.of(valueToIndex.get(rem), i));
|
return Optional.of(Pair.of(valueToIndex.get(remainder), i));
|
||||||
}
|
}
|
||||||
if (!valueToIndex.containsKey(values[i])) {
|
if (!valueToIndex.containsKey(values[i])) {
|
||||||
valueToIndex.put(values[i], i);
|
valueToIndex.put(values[i], i);
|
||||||
|
@ -62,10 +62,10 @@ public class FibonacciSearch implements SearchAlgorithm {
|
|||||||
Integer[] integers = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
|
Integer[] integers = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
|
||||||
|
|
||||||
int size = integers.length;
|
int size = integers.length;
|
||||||
Integer shouldBeFound = 128;
|
Integer targetValue = 128;
|
||||||
FibonacciSearch fsearch = new FibonacciSearch();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,13 +75,13 @@ final class WordLadder {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
wordsChars[j] = c;
|
wordsChars[j] = c;
|
||||||
String newWord = String.valueOf(wordsChars);
|
String transformedWord = String.valueOf(wordsChars);
|
||||||
if (newWord.equals(endWord)) {
|
if (transformedWord.equals(endWord)) {
|
||||||
return level + 1;
|
return level + 1;
|
||||||
}
|
}
|
||||||
if (set.contains(newWord)) {
|
if (set.contains(transformedWord)) {
|
||||||
set.remove(newWord);
|
set.remove(transformedWord);
|
||||||
queue.offer(newWord);
|
queue.offer(transformedWord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wordsChars[j] = originalChars;
|
wordsChars[j] = originalChars;
|
||||||
|
Loading…
Reference in New Issue
Block a user