8000 Added solution to leetcode 211 by YuvrajSingh808 · Pull Request #608 · dheeraj-2000/dsalgo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added solution to leetcode 211 #608

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Node:
def __init__(self):
self.children = {}
self.endOfWord = False
class WordDictionary:

def __init__(self):
self.root = Node()

def addWord(self, word: str) -> None:
cur = self.root
for c in word:
if c not in cur.children:
cur.children[c] = Node()
cur = cur.children[c]
cur.endOfWord = True

def search(self, word: str, root = None) -> bool:
if root is None:
cur = self.root
else:
cur = root
for c in enumerate(word):
if c[1] == '.':
for k in cur.children.keys():
if self.search(word[(c[0] + 1):], cur.children[k]):
return True
return False

else:
if c[1] not in cur.children:
return False
cur = cur.children[c[1]]
return cur.endOfWord

0