Last time I tried to solve a problem in leetcode but my solution is getting "Runtime Error: AddressSanitizer: DEADLY SIGNAL".
The complete Error message is
AddressSanitizer:DEADLYSIGNAL ================================================================= ==30==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x0000002b0452 bp 0x7ffd8e6682e0 sp 0x7ffd8e667a78 T0) ==30==The signal is caused by a READ memory access. ==30==Hint: this fault was caused by a dereference of a high value address (see register values below). Dissassemble the provided pc to learn which register was used. #3 0x7f73671f7d6b (/lib/x86_64-linux-gnu/libstdc++.so.6+0x144d6b) #10 0x7f7366d6b0b2 (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) AddressSanitizer can not provide additional info. ==30==ABORTING
The problem link is https://leetcode.com/problems/word-pattern/
Here is my solution
class Solution {
public:
bool wordPattern(string pattern, string s) {
vector<string>vec;
string tmp = "";
for(int i=0 ; i<s.size() ; i++){
if(s[i] == ' '){
vec.push_back(tmp);
tmp.clear();
continue;
}
tmp += s[i];
}
map<char , set<string> > mp;
for(int i=0 ; i<pattern.size() ; i++){
mp[pattern[i]].insert(vec[i]);
}
bool flag = 0;
for(int i=0 ; i<pattern.size() ; i++){
char x = pattern[i];
if(mp[x].size() != 1)
flag = 1;
}
return !flag;
}
};
I don't get where is the problem...
Aucun commentaire:
Enregistrer un commentaire