Skip to content

Instantly share code, notes, and snippets.

@Adrodoc
Created August 12, 2019 19:56
Show Gist options
  • Save Adrodoc/5a4620fac2d6079056a3c25bc11ca163 to your computer and use it in GitHub Desktop.
Save Adrodoc/5a4620fac2d6079056a3c25bc11ca163 to your computer and use it in GitHub Desktop.
public boolean containsSuffix(String str) {
Node node = root;
while (true) {
if (str.isEmpty()) {
return node.children.isEmpty(); // return node.isleaf
}
node = node.children.get(String.valueOf(str.charAt(0)));
if (node == null) {
return false;
}
String label = node.getlabel(s);
if (str.startsWith(label)) {
str = str.substring(label.length());
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment