Question for "expected ‘;’ at end of member declaration"


  • 0
    L

    I am running fine at Visual Studio and meet some problems at leetcode.
    The error is "Line 4: expected ‘;’ at end of member declaration".
    Could someone give me a hint? Thank you.

    class DictNode {
    public:
    	bool complete = 0;
    	std::map<char, DictNode*> children = std::map<char, DictNode*> ();
    	DictNode(){};
    }
    
    class WordDictionary {
    public:
    	DictNode* root  = new DictNode();
    	void addWord(string word) {
    		if (root == NULL) {
    			root = new DictNode();
    		}
    		addWordhelper(word, root);
    		return;
    	}
    	void addWordhelper(string word, DictNode* root) {
    		if (root == NULL) return;
    		if (word.size() == 0) {
    			root->complete = 1;
    			return;
    		}
    
    		if (root->children.find(word[0])!=root->children.end()) {
    			addWordhelper(word.substr(1), root->children[word[0]]);
    		}
    		else {
    			root->children[word[0]] = new DictNode();
    			addWordhelper(word.substr(1), root->children[word[0]]);
    		}
    		return;
    	}
    
    	bool search(string word) {
    		return searchhelper(word, root);
    	}
    
    	bool searchhelper(string word, DictNode* root) {
    		if (word == "") return root->complete;
    		if (word[0]!= '.') {
    			if (root->children.find(word[0])!=root->children.end()) {
    				return searchhelper(word.substr(1), root->children[word[0]]);
    			}
    			else return false;
    		}
    		else {
    			bool a = false;
    			for (auto it : root->children) {
    				a = a || (searchhelper(word.substr(1), root->children[it.first]));
    			}
    			return a;
    		}
    	}
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.