C++ non recursive way,but cannot compile.


  • 0
    Q

    #include <map>
    #include <vector>
    #include <string>
    #include <iostream>

    using namespace std;

    typedef struct {
    int col;
    int row;
    }Position;

    //typedef unordered_map<Position,bool> Map;

    map<Position,int> Mark_node;

    //map<Position,int>::iterator find_char;
    bool match(vector<vector<char> > &board, string word){
    vector<char> temp_vector;
    Position chr;

    for(int i=0;i<word.size();i++){
        
        for(int j=0;j<board.size();j++){
            temp_vector=board[j];
            for(int k=0;k<temp_vector.size();k++){
                if(word[i]==temp_vector[k]){
                    chr.col=j;
                    chr.row=k;
                    auto it=Mark_node.find(chr);
                    if(it==Mark_node.end()){
                        return false;
                    }
                    else{
                        Mark_node[chr]=1;
                    }
                    
                }
                
                
            }
        }
    }
    
    return true;
    

    }

    int main(){
    vector<vector<char> > char_vector;
    vector<char> temp1,temp2,temp3;
    temp1[0]='A';
    temp1[1]='B';
    char_vector[0]=temp1;
    temp2[0]='C';
    temp2[1]='D';
    char_vector[1]=temp2;

    string word="ABCCED";
    bool jude=match(char_vector,word);
    return 1;
    

    }


Log in to reply
 

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