Skip to content

Commit 3819334

Browse files
committed
suffix array find string
1 parent 5eccfe3 commit 3819334

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Suffix-Array/sa.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,15 @@ struct SA {
3939
}
4040
}
4141
}
42+
bool findString(const string& t, int spos, int epos) {
43+
int lo = 0, hi = n-1;
44+
int len = epos-spos+1;
45+
while(lo<hi) {
46+
int mid = (lo+hi)/2;
47+
int res = s.compare(sa[mid], len, t, spos, len);
48+
(res>=0) ? hi = mid : lo = mid+1;
49+
}
50+
return s.compare(sa[lo], len, t, spos, len)==0;
51+
}
52+
bool findString(const string& t) {return findString(t, 0, t.size()-1);}
4253
};

0 commit comments

Comments
 (0)