forked from codereport/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path140_Problem_1.cpp
More file actions
21 lines (18 loc) · 775 Bytes
/
Copy path140_Problem_1.cpp
File metadata and controls
21 lines (18 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// code_report Solution
// Video Link: https://youtu.be/cClOEG-_dns
// Problem Link: https://leetcode.com/problems/occurrences-after-bigram/
// Wandbox Link: https://wandbox.org/permlink/AEhEejSPeDer55A5
// C++20 Ranges / Ranges-v3
namespace rv = ranges::view;
namespace ra = ranges::action;
auto findOcurrences(string s, string a, string b) -> vector<string> {
auto t = s | rv::split(' ')
| ranges::to<vector<string>>;
return t | rv::sliding(3)
| rv::filter([a, b] (auto rng) {
return a == *ranges::cbegin(rng) &&
b == *next(ranges::cbegin(rng)); })
| rv::transform([](auto rng) {
return *ranges::crbegin(rng); })
| ranges::to<vector<string>>;
}