#include #include "map_vec.h" /** * 2 <= nums.length <= 104 * -109 <= nums[i] <= 109 * -109 <= target <= 109 * 只会存在一个有效答案 * * 来源:力扣(LeetCode) * 链接:https://leetcode.cn/problems/two-sum * 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 */ TEST(TwoSumTest, BasicAssertions) { std::vector output, input; int target; /** * 示例 1: * 输入:nums = [2,7,11,15], target = 9 * 输出:[0,1] * 解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。 */ input.resize(4); input = {2, 7, 11, 15}; target = 9; output = yaha::two_sum(input, target); ASSERT_EQ(output.size(), 2); ASSERT_EQ(output[0], 0); ASSERT_EQ(output[1], 1); /** * 示例 2: * 输入:nums = [3,2,4], target = 6 * 输出:[1,2] */ input.resize(3); input = {3, 2, 4}; target = 6; output = yaha::two_sum(input, target); ASSERT_EQ(output.size(), 2); ASSERT_EQ(output[0], 1); ASSERT_EQ(output[1], 2); /** * 示例 3: * 输入:nums = [3,3], target = 6 * 输出:[0,1] */ input.resize(2); input = {3, 3}; target = 6; output = yaha::two_sum(input, target); ASSERT_EQ(output.size(), 2); ASSERT_EQ(output[0], 0); ASSERT_EQ(output[1], 1); }