-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Description
Bug Report for https://neetcode.io/problems/search-for-word-ii
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

The compiler does not appear to accept my java code for some reason. It shows Compiler Error (NZEC)
Steps for reproducing
- Select java as programming language
- Paste the following code into the solution class:
`
class Solution {
private static class ReturnType2 {
final int var1, var2;
ReturnType2(int var1, int var2) {
this.var1 = var1;
this.var2 = var2;
}
@Override
public boolean equals(Object other) {
ReturnType2 s = (ReturnType2) other;
return s.var1 == var1 && s.var2 == var2;
}
@Override
public int hashCode() {
return Integer.hashCode(31*var1 + 65535*var2);
}
}
private boolean probeWord(String word, ReturnType2 position, HashSet<ReturnType2> exclusion, char[][] board, int i) {
/*for (ReturnType2 posTest : exclusion)
if (posTest.equals(position))
return false;*/
if (!exclusion.contains(position) && position.var1 >= 0 && position.var2 >= 0 && position.var2 < board.length && position.var1 < board[position.var2].length && board[position.var2][position.var1] == word.charAt(i)) {
if (word.length() - i == 1)
return true;
else {
exclusion.add(position);
boolean out =
probeWord(word, new ReturnType2(position.var1-1, position.var2), exclusion, board, i + 1) ||
probeWord(word, new ReturnType2(position.var1+1, position.var2), exclusion, board, i + 1) ||
probeWord(word, new ReturnType2(position.var1, position.var2-1), exclusion, board, i + 1) ||
probeWord(word, new ReturnType2(position.var1, position.var2+1), exclusion, board, i + 1);
exclusion.remove(position);
return out;
}
} else
return false;
}
public List<String> findWords(char[][] board, String[] words) {
LinkedList<String> out = new LinkedList<>();
Outer_Loop: for (String word : words)
for (int i = 0; i < board.length; i++)
for (int j = 0; j < board[i].length; j++)
if (probeWord(word, new ReturnType2(j, i), new HashSet<>(), board, 0)) {
out.add(word);
continue Outer_Loop;
}
return out;
}
}
`
- Execute the code by submitting it
- Look for compiler error:
run.sh: line 1: 3 Killed /usr/local/jdk17/bin/java --module-path /usr/local/javafx-sdk-22.0.2/lib --add-modules javafx.web,javafx.fxml,javafx.swing,javafx.controls,javafx.media,javafx.base,javafx.graphics Main
Metadata
Metadata
Assignees
Labels
No labels