Skip to content

Commit

Permalink
Create Implement _Trie.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
onemask authored May 15, 2020
1 parent 56fad05 commit b5c416d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Implement _Trie.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Trie {
/** Initialize your data structure here. */
private val tries = mutableListOf<String>()

/** Inserts a word into the trie. */
fun insert(word: String) = tries.add(word)


/** Returns if the word is in the trie. */
fun search(word: String)= tries.contains(word)

/** Returns if there is any word in the trie that starts with the given prefix. */
fun startsWith(prefix: String) = tries.find { it.startsWith(prefix) } != null
}

0 comments on commit b5c416d

Please sign in to comment.