برنامه نویسی

LeetCode: 211. طراحی ساختار داده کلمات افزودن و جستجو (و دیگران)

// Solution @ Sergey Leschev

class TrieNode {
    var children: [Character: TrieNode]
    var isWord: Bool

    init() {
        children = [:]
        isWord = false
    }
}

class WordDictionary {
    var root: TrieNode

    init() {
        root = TrieNode()
    }

    func addWord(_ word: String) {
        var node = root
        for c in word {
            if let child = node.children[c] {
                node = child
            } else {
                let child = TrieNode()
                node.children[c] = child
                node = child
            }
        }
        node.isWord = true
    }

    func search(_ word: String) -> Bool {
        return searchHelper(Array(word), 0, root)
    }

    private func searchHelper(_ word: [Character], _ index: Int, _ node: TrieNode) -> Bool {
        if index == word.count {
            return node.isWord
        }

        let c = word[index]

        if c != "." {
            if let child = node.children[c] {
                return searchHelper(word, index+1, child)
            }
            return false
        } else {
            for child in node.children.values {
                if searchHelper(word, index+1, child) {
                    return true
                }
            }
            return false
        }
    }
}

وارد حالت تمام صفحه شوید

از حالت تمام صفحه خارج شوید


راه حل های LeetCode من / سوئیفت
https://github.com/sergeyleschev/leetcode-swift

راه حل های LeetCode / TypeScript من
https://github.com/sergeyleschev/leetcode-typescript


مخاطب
من تمرکز واضحی بر زمان عرضه به بازار دارم و بدهی فنی را در اولویت قرار نمی دهم. و من در فعالیت های پیش فروش/RFX به عنوان معمار سیستم، تلاش های ارزیابی برای موبایل (iOS-Swift، Android-Kotlin)، Frontend (React-TypeScript) و Backend (NodeJS-.NET-PHP-Kafka-SQL) شرکت کردم. -NoSQL). و همچنین کار پیش فروش را به عنوان یک مدیر ارشد فناوری از فرصت تا پیشنهاد از طریق انتقال دانش به تحویل موفق تشکیل دادم.

🛩️ #استارتاپ ها #مدیریت #cto #swift #typescript #پایگاه داده
📧 ایمیل: sergey.leschev@gmail.com
👋 لینکدین: https://www.linkedin.com/in/sergeyleschev/
👋 LeetCode: https://leetcode.com/sergeyleschev/
👋 توییتر: https://twitter.com/sergeyleschev
👋 Github: https://github.com/sergeyleschev
🌎 وب سایت: https://sergeyleschev.github.io

نوشته های مشابه

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

دکمه بازگشت به بالا