You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
380 B
TypeScript
21 lines
380 B
TypeScript
export function intersectionSortedArray(a: number[], b: number[]): number[] {
|
|
let res: number[] = [];
|
|
let aI = 0;
|
|
let bI = 0;
|
|
|
|
while (aI < a.length && bI < b.length) {
|
|
let aValue = a[aI];
|
|
let bValue = b[bI];
|
|
|
|
if (aValue === bValue) {
|
|
res.push(aValue);
|
|
aI++;
|
|
bI++;
|
|
} else {
|
|
aValue < bValue ? aI++ : bI++;
|
|
}
|
|
}
|
|
|
|
return res;
|
|
};
|