Need help with runtime error


  • 0
    K

    I tried to solve using Trie. Below code worked for smaller test cases but it's giving Runtime Error Message:
    Line 35: member access within misaligned address 0x64776b7a7820796a for type 'struct Node', which requires 8 byte alignment
    for
    ["ll","now","uap","xn","mtxbk","en","ifm","tty","j","i","ezfyt","k","wpl","rnw","yuuax","fvy","km","ewko","suvti","ddv","dzrfc","f","nkyb","cpme","ensn","bjh","soacg","gd","a","lcwbs","pjze","bwlm","svk","um","rpy","mwyo","iqj","hsiki","yv","sdtd","jns","cfadn","gxotu","uoj","xzao","ug","qnlvo","fgbp","dx","m","wp","yoyf","fyzl","z","mjcso","s","b","u","ad","zrerd","pyxxs","g","pgakz","v","owrpk","slhb","rprt"]
    "zsyrupfxkwyzxnfkb nvsxmebaqwtejtdikjdb owabmqdbbo ltorldoq w xuyjdxmov hamjfoeae sqlftbmeywleeiscndj p jxu zoslotzcttjnbotki wyhyyueudixnorx vdglkopp cfakarjbf aboaszt onbffyfr cjpfrjqkolnamygqqj uwphkibxemxensz zouhcybstkbdyg ubfwglanyquhwlrglvc givqubayvmrvholkcke vkvyjrjraiollmlt npofa ffwnkttyp gwabsiibv vy tyrsvbuxticx e zfksmowe pdrlwocngdlpv n ouylngqjxilaqlkn zbxhafxxpvjkqpwdsy ssnsy itufigmudtvbv jw sfupomzekekabo caas nkmgrpuhskf rhifdognhfdoo pzecptqfzfvoa jzdlf zkcerlkxxqjy xzkwdgergjosa hgbovwtpzcpwtlwy tly ibtefvaozlsxo jopulkb mmgngozepqlpnqhvkn vwlbuktoipbncdnzhud urnocwb yfsrzjtvbt ybqbkflsz evlxlycwmlttaxlxdfjg xk tjjruytuikaucpcfxr ktbgnifciauv asvclppedfhf mldkna kbqtlbdwgftpzbojvsxm smzgn kyx zgclfw nsywjvgdicwccdoknm rhelltyrist fcijinwjev t" big enough input size.

    Can you please help me understand why the error?

    My Code :

    class Solution {
    public:
        struct Node {
            vector<Node*> n;
            bool b;
            Node() : b(false) {
                n.resize(26,NULL);
            }
        };
        Node *trie;
        void construct_trie(vector<string> &dict) {
            trie=new Node();
            int i,sz=dict.size(),j;
            Node *cur,*temp;
            for(i=0;i<sz;i++) {
                cur=trie;
                for(j=0;j<dict[i].length();j++) {
                    if((cur->n)[dict[i][j]-'a'])
                        cur=(cur->n)[dict[i][j]-'a'];
                    else {
                        temp=new Node();
                        (cur->n)[dict[i][j]-'a']=temp;
                        cur=temp;
                    }
                }
                cur->b=true;
            }
        }
        string replaceWords(vector<string>& dict, string sentence) {
            construct_trie(dict);
            string ans="";
            int i=0,sz=sentence.length(),j;
            Node *cur=trie;
            while(i<sz) {
                if(cur->b) {
                    while(i<sz && sentence[i]!=' ')
                        i++;
                    if(i<sz)
                        ans+=' ';
                    i++;
                    cur=trie;
                }
                else if((cur->n)[sentence[i]-'a']) {
                    cur=(cur->n)[sentence[i]-'a'];
                    ans+=sentence[i];
                    i++;
                }
                else {
                    while(i<sz && sentence[i]!=' ') {
                        ans+=sentence[i];
                        i++;
                    }
                    if(i<sz)
                        ans+=' ';
                    i++;
                    cur=trie;
                }
            }
            return ans;
        }
    };
    

Log in to reply
 

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