File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
implement-trie-prefix-tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ '''
2+ ๋ฌธ์ : ํน์ ๋ช
๋ น์ด ์ฃผ์ด์ก์ ๋, ํธ๋ผ์ด(Trie) ์๋ฃ๊ตฌ์กฐ๋ฅผ ๊ตฌํํ๋ ์ฝ๋๋ฅผ ์์ฑํ์์ค.
3+ ํ์ด: ๋จ์ํ ๋ฌธ์์ด์ ์ ์ฅํ๋ ๋ฆฌ์คํธ๋ฅผ ์ฌ์ฉํ์ฌ ํธ๋ผ์ด ์๋ฃ๊ตฌ์กฐ์ ๊ธฐ๋ฅ์ ๊ตฌํํฉ๋๋ค.
4+ '''
5+
6+
7+ class Trie :
8+
9+ def __init__ (self ):
10+ self .arr = []
11+
12+ def insert (self , word : str ) -> None :
13+ self .arr .append (word )
14+
15+ def search (self , word : str ) -> bool :
16+ for i in self .arr :
17+ if i == word :
18+ return True
19+ return False
20+
21+ def startsWith (self , prefix : str ) -> bool :
22+ n = len (prefix )
23+ for i in self .arr :
24+ if i [:n ] == prefix :
25+ return True
26+ return False
27+
28+
29+ # Your Trie object will be instantiated and called as such:
30+ # obj = Trie()
31+ # obj.insert(word)
32+ # param_2 = obj.search(word)
33+ # param_3 = obj.startsWith(prefix)
You canโt perform that action at this time.
0 commit comments