I am not sure where your code goes wrong, but you can try the following:
private static final char toReplace = '#';
private static final Set<Character> replacements = new HashSet<>(Arrays.asList('X', 'O'));
private static Set<String> UnHide(String s) {
Set<String> result = new HashSet<>();
result.add("");
for (char c : s.toCharArray()){
Set<String> updatedResult = new HashSet<>();
for (String temp : result) {
if (toReplace == c) {
for (Character replacement : replacements) {
updatedResult.add(temp + replacement);
}
} else {
updatedResult.add(temp + c);
}
}
result = updatedResult;
}
return result;
}
Then calling:
String str = "XOXX#OO#XO";
System.out.println(UnHide(str));
outputs:
[XOXXOOOXXO, XOXXXOOOXO, XOXXOOOOXO, XOXXXOOXXO]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…