Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add solutions to lc problem: No.3036 #2343

Merged
merged 39 commits into from
Feb 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f4b58ec
feat: add solutions to lc problem: No.3033
Nothing-avil Feb 11, 2024
28d320d
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
bd08e77
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
bcc78e5
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
fcb8cff
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
bffd742
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
9da0d92
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
9d92cbf
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
90b9198
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
a1fee31
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
00bacf9
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
b778ba5
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
0a9cf6c
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
d80fccd
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
7df70e1
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
e0507ce
style: format code and docs with prettier
Nothing-avil Feb 11, 2024
22517c1
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
a941ad3
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
d34a5e0
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
5f429be
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
2990d85
feat: add solutions to lc problem: No.3034
Nothing-avil Feb 11, 2024
1f0f649
Merge branch 'doocs:main' into main
Nothing-avil Feb 12, 2024
e00919a
Merge branch 'doocs:main' into main
Nothing-avil Feb 13, 2024
bba266c
Merge branch 'doocs:main' into main
Nothing-avil Feb 14, 2024
c242103
feat: add solutions to lc problem: No.3036
Nothing-avil Feb 14, 2024
432451a
feat: add solutions to lc problem: No.3036
Nothing-avil Feb 14, 2024
b8ca15e
feat: add solutions to lc problem: No.3036
Nothing-avil Feb 14, 2024
3874792
feat: add solutions to lc problem: No.3036
Nothing-avil Feb 14, 2024
f76f1ed
feat: add solutions to lc problem: No.3036
Nothing-avil Feb 14, 2024
4d0afb6
feat: add solutions to lc problem: No.3036
Nothing-avil Feb 14, 2024
eec158c
feat: add solutions to lc problem: No.3036
Nothing-avil Feb 14, 2024
1acdb34
style: format code and docs with prettier
Nothing-avil Feb 14, 2024
80427df
feat: add solutions to lc problem: No.3036
Nothing-avil Feb 14, 2024
db0355c
feat: add solutions to lc problem: No.3036
Nothing-avil Feb 14, 2024
7e482bf
Update README.md
yanglbme Feb 15, 2024
7fa5e9a
Update README_EN.md
yanglbme Feb 15, 2024
0e917c8
Update Solution.go
yanglbme Feb 15, 2024
b1f7fb3
Update README.md
yanglbme Feb 15, 2024
e29bc0e
Update README_EN.md
yanglbme Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add solutions to lc problem: No.3034
Nothing-avil authored Feb 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 0a9cf6cd3c7bc64472749c90b18b29ebbcc1fb8f
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
class Solution {
public:
int countMatchingSubarrays(vector<int>& nums, vector<int>& pattern) {
assert(nums.size() >= 2 && nums.size() <= 100);
for (int x : nums) {
assert(x >= 1 && x <= 1000000000);
}
const int m = pattern.size();
assert(m >= 1 && m < nums.size());
for (int x : pattern) {
assert(abs(x) <= 1);
}
int r = 0;
for (int i = 0; i + m < nums.size(); ++i) {
bool mark = true;
for (int k = 0; mark && k < m; ++k) {
mark = (pattern[k] == 1 && nums[i + k + 1] > nums[i + k])
|| (pattern[k] == 0 && nums[i + k + 1] == nums[i + k])
|| (pattern[k] == -1 && nums[i + k + 1] < nums[i + k]);
int n = nums.size();
int m = pattern.size();
int c = 0;
for (int i = 0; i <= n - m - 1; i++) {
bool flag = true;
for (int j = 0; j < m; j++) {
if ((pattern[j] == 1 && nums[i + j + 1] <= nums[i + j]) ||
(pattern[j] == 0 && nums[i + j + 1] != nums[i + j]) ||
(pattern[j] == -1 && nums[i + j + 1] >= nums[i + j])) {
flag = false;
break;
}
}
if (flag) {
c++;
}
r += mark;
}
return r;
return c;
}
};