-
-
Notifications
You must be signed in to change notification settings - Fork 305
[doh6077] WEEK 05 Solutions #2164
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
Conversation
|
|
||
| # 208. Implement Trie (Prefix Tree) | ||
| class Trie: | ||
|
|
||
| def __init__(self): | ||
| self.list = [] | ||
|
|
||
|
|
||
| def insert(self, word: str) -> None: | ||
| self.list.append(word) | ||
|
|
||
|
|
||
| def search(self, word: str) -> bool: | ||
| if word in self.list: | ||
| return True | ||
| else: | ||
| return False | ||
|
|
||
|
|
||
| def startsWith(self, prefix: str) -> bool: | ||
| for i, value in enumerate(self.list): | ||
| if value.startswith(prefix): | ||
| return True | ||
| return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 파일을 다른 폴더에 넣으신 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그리고, 통과는 되었지만, Trie 구조와는 거리가 먼 것으로 보여서, 시간이 되시면, 한 번 만들어 보시는 것도 좋을 것 같습니다!
| start = i - len(w) | ||
| if start >= 0 and dp[start] and s[start:i] == w: | ||
| dp[i] = True | ||
| break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 문제를 LIS dp 문제와 유사하게 풀 수 있었군요. 좋은 경험이었습니다.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!