Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bitapSearch(text: string, pattern: string): string | null {
- const m = pattern.length;
- if (m === 0) {
- return text;
- }
- // Initialize the bit array R.
- const R: boolean[] = new Array(m + 1).fill(false);
- R[0] = true;
- for (let i = 0; i < text.length; i++) {
- // Update the bit array.
- for (let k = m; k >= 1; k--) {
- R[k] = R[k - 1] && (text[i] === pattern[k - 1]);
- }
- if (R[m]) {
- return text.substring(i - m + 1, i + 1);
- }
- }
- return null;
- }
- // Example usage:
- const text = "this is a simple example";
- const pattern = "simple";
- const result = bitapSearch(text, pattern);
- console.log(result); // Output: "simple"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement