Files
leetcode/tests/test_3397.cpp
2025-12-05 22:41:20 +08:00

32 lines
831 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// This file is generated by mkfile.py
// Date: 2025-10-18
#include <solution/3397.h>
#include <gtest/gtest.h>
class MaxDistinctElementsTest : public ::testing::Test {
protected:
void AssertMaxDistinctElements(std::vector<int> nums, int k, int expected) {
int* arr = new int[nums.size()];
std::copy(nums.begin(), nums.end(), arr);
int result = maxDistinctElements(arr, nums.size(), k);
ASSERT_EQ(result, expected);
delete[] arr;
}
};
// 示例 1
TEST_F(MaxDistinctElementsTest, Example1) {
// 输入nums = [1,2,2,3,3,4], k = 2
// 输出6
AssertMaxDistinctElements({1, 2, 2, 3, 3, 4}, 2, 6);
}
// 示例 2
TEST_F(MaxDistinctElementsTest, Example2) {
// 输入nums = [4,4,4,4], k = 1
// 输出3
AssertMaxDistinctElements({4, 4, 4, 4}, 1, 3);
}