This commit is contained in:
2025-07-17 20:43:48 +08:00
parent e924811683
commit 4b5d8c5c22
3 changed files with 41 additions and 0 deletions

11
include/solution/3202.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef INC_3202_H
#define INC_3202_H
#ifdef __cplusplus
extern "C"
{
#endif
int maximumLength(int *nums, int numsSize, int k);
#ifdef __cplusplus
}
#endif
#endif

5
src/3202.c Normal file
View File

@@ -0,0 +1,5 @@
#include <solution/3202.h>
int maximumLength(int *nums, int numsSize, int k)
{
}

25
tests/test_3202.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include <gtest/gtest.h>
#include <solution/3202.h>
class MaximumLengthWithKTest : public ::testing::Test
{
protected:
void AssertMaximumLength(const std::vector<int> &nums, int k, int expected)
{
int *arr = const_cast<int *>(nums.data());
int result = maximumLength(arr, nums.size(), k);
EXPECT_EQ(result, expected);
}
};
// 示例 1nums = [1,2,3,4,5], k = 2 => 输出 5
TEST_F(MaximumLengthWithKTest, AllIncreasing)
{
AssertMaximumLength({1, 2, 3, 4, 5}, 2, 5);
}
// 示例 2nums = [1,4,2,3,1,4], k = 3 => 输出 4
TEST_F(MaximumLengthWithKTest, AlternatingValidPairs)
{
AssertMaximumLength({1, 4, 2, 3, 1, 4}, 3, 4);
}