Skip to content

Commit 42091e9

Browse files
committed
Add solution #1078
1 parent 48d7a03 commit 42091e9

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,126 LeetCode solutions in JavaScript
1+
# 1,127 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -865,6 +865,7 @@
865865
1072|[Flip Columns For Maximum Number of Equal Rows](./solutions/1072-flip-columns-for-maximum-number-of-equal-rows.js)|Medium|
866866
1073|[Adding Two Negabinary Numbers](./solutions/1073-adding-two-negabinary-numbers.js)|Medium|
867867
1074|[Number of Submatrices That Sum to Target](./solutions/1074-number-of-submatrices-that-sum-to-target.js)|Hard|
868+
1078|[Occurrences After Bigram](./solutions/1078-occurrences-after-bigram.js)|Easy|
868869
1079|[Letter Tile Possibilities](./solutions/1079-letter-tile-possibilities.js)|Medium|
869870
1081|[Smallest Subsequence of Distinct Characters](./solutions/1081-smallest-subsequence-of-distinct-characters.js)|Medium|
870871
1092|[Shortest Common Supersequence](./solutions/1092-shortest-common-supersequence.js)|Hard|
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* 1078. Occurrences After Bigram
3+
* https://leetcode.com/problems/occurrences-after-bigram/
4+
* Difficulty: Easy
5+
*
6+
* Given two strings first and second, consider occurrences in some text of the form "first second
7+
* third", where second comes immediately after first, and third comes immediately after second.
8+
*
9+
* Return an array of all the words third for each occurrence of "first second third".
10+
*/
11+
12+
/**
13+
* @param {string} text
14+
* @param {string} first
15+
* @param {string} second
16+
* @return {string[]}
17+
*/
18+
var findOcurrences = function(text, first, second) {
19+
const words = text.split(' ');
20+
const result = [];
21+
22+
for (let i = 0; i < words.length - 2; i++) {
23+
if (words[i] === first && words[i + 1] === second) {
24+
result.push(words[i + 2]);
25+
}
26+
}
27+
28+
return result;
29+
};

0 commit comments

Comments
 (0)