Leetcode Weekly Contest 332 | Substring XOR Queries | latest Contest

preview_player
Показать описание
#programming #leetcode #python
#leetcode
#332
#contest332
#Contestsolution332
#leetCodelatestcontest
#india
#CounttheNumberOfFairPairs
#substringxorqueries
#SubStringXorQueries
#programming
#coding
#coders
#programming #programmer #programmers #developer #coder #programmingmemes #coders #coding #frontenddeveloper #backenddeveloper #html #softwaredeveloper #hacking #python
Рекомендации по теме
Комментарии
Автор

My Code :-
class Solution {
public:
vector<vector<int>> substringXorQueries(string s, vector<vector<int>>& query) {
vector<vector<int>>ans;
int n=query.size();int m=s.size();
vector<int>v;
for(int i=0;i<n;i++){

}
map<int, int>mp;
for(int i=0;i<m;i++){
if(s[i]=='1'){
long long val=0;
int ind=i;
while(ind<m &&
val=2*val;
if(s[ind]=='1'){
val++;
}
if(mp.find(val)==mp.end()){
mp[val]=i;
}ind++;
}
}
else{
if(mp.find(0)==mp.end())
mp[0]=i;
}
}
for(int i=0;i<n;i++){
int x=v[i];

if(mp.find(x)==mp.end()){
ans.push_back({-1, -1});
}
else{
int id=mp[x];
int cnt=1;
x=x/2;
while(x>0){
cnt++;
x=x/2;
}
ans.push_back({id, id+cnt-1});
}
}
return ans;
}
};

EngineerPrabhatSingh
welcome to shbcf.ru