From 4ae34df8ce3118338fd93de5b3dbf13eb487a72f Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Wed, 28 Jan 2026 15:00:25 +0700 Subject: [PATCH 1/6] LC - two_sum --- CMakeLists.txt | 2 ++ src/leetcode/arrays/two_sum/TwoSum.cpp | 48 ++++++++++++++++++++++++++ src/leetcode/arrays/two_sum/TwoSum.h | 34 ++++++++++++++++++ tests/two_sum_unittest.cpp | 36 +++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 src/leetcode/arrays/two_sum/TwoSum.cpp create mode 100644 src/leetcode/arrays/two_sum/TwoSum.h create mode 100644 tests/two_sum_unittest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 79cf91a..7edc23c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,11 +126,13 @@ set(APP_SOURCES "src/core/datatypes/container/unordered/UnorderedMap.cpp" "src/core/expression/Lambda.cpp" "src/core/expression/FunctionPointer.cpp" + "src/leetcode/arrays/two_sum/TwoSum.cpp" ) # Test files set(APP_TESTS "tests/DeleteMeTest.cpp" + "tests/two_sum_unittest.cpp" ) # ---------------------------------------------------------------------------------------- diff --git a/src/leetcode/arrays/two_sum/TwoSum.cpp b/src/leetcode/arrays/two_sum/TwoSum.cpp new file mode 100644 index 0000000..b6c73c3 --- /dev/null +++ b/src/leetcode/arrays/two_sum/TwoSum.cpp @@ -0,0 +1,48 @@ +#include "TwoSum.h" + +/** + * S1: Using for-loop-index + * Time complexity: O(n2) + * Space complexity: O(1) + */ +std::vector Solution::twoSum(const std::vector& nums, int target) { + for (int i = 0; i < nums.size(); ++i) { + int diff = target - nums.at(i); + for (int j = i + 1; j < nums.size(); ++j) { + if (diff == nums.at(j)) { + return std::vector{i, j}; + } + } + } + + // no solution + return std::vector{-1, -1}; +} + +// #include +// /** +// * 3 1 4 +// * ===== +// * 3 1 4 +// * ----- +// * 0 1 2 +// * ===== +// * Time complexity: O(n) +// * Space complexity: O(n) +// */ +// std::vector Solution::twoSum(const std::vector& nums, int target) { +// std::unordered_map numMap{}; +// for (int i = 0; i < nums.size(); ++i) { +// int xkey = nums[i]; +// int ykey = target - nums[i]; +// if (numMap.find(ykey) != nullptr) { +// return std::vector{numMap.at(ykey), i}; +// } + +// // save vector to map +// numMap.insert(std::pair(xkey, i)); +// } + +// // no solution +// return std::vector{-1, -1}; +// } diff --git a/src/leetcode/arrays/two_sum/TwoSum.h b/src/leetcode/arrays/two_sum/TwoSum.h new file mode 100644 index 0000000..78fba08 --- /dev/null +++ b/src/leetcode/arrays/two_sum/TwoSum.h @@ -0,0 +1,34 @@ +//cppcheck-suppress-file [functionStatic] + +// Given an array of integers nums and an integer target, return indices[ˈɪn.də.siːz] of the two numbers such that they add up to target. + +// You may assume that each input would have exactly one solution, and you may not use the same element twice. +// You can return the answer in any order. + +// Example 1: +// Input: nums = [2,7,11,15], target = 9 +// Output: [0,1] +// Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. + +// Example 2: +// Input: nums = [3,2,4], target = 6 +// Output: [1,2] + +// Example 3: +// Input: nums = [3,3], target = 6 +// Output: [0,1] + +// Constraints: +// 2 <= nums.length <= 104 +// -109 <= nums[i] <= 109 +// -109 <= target <= 109 +// Only one valid answer exists. + +// Follow-up: Can you come up with an algorithm that is less than O(n2) time complexity ? + +#pragma once +#include +class Solution { + public: + std::vector twoSum(const std::vector& nums, int target); +}; diff --git a/tests/two_sum_unittest.cpp b/tests/two_sum_unittest.cpp new file mode 100644 index 0000000..eabfb41 --- /dev/null +++ b/tests/two_sum_unittest.cpp @@ -0,0 +1,36 @@ +#include +#include "../src/leetcode/arrays/two_sum/TwoSum.h" + +struct TestCase { + std::vector nums; + int target; + std::vector expected; +}; + +TEST(TwoSum, Case1) { + TestCase tc = {.nums{2, 7, 11, 15}, .target{9}, .expected{0, 1}}; + Solution s{}; + + EXPECT_EQ(tc.expected, s.twoSum(tc.nums, tc.target)); +} + +TEST(TwoSum, Case2) { + TestCase tc = {.nums{3, 2, 4}, .target{6}, .expected{1, 2}}; + Solution s{}; + + EXPECT_EQ(tc.expected, s.twoSum(tc.nums, tc.target)); +} + +TEST(TwoSum, Case3) { + TestCase tc = {.nums{3, 3}, .target{6}, .expected{0, 1}}; + Solution s{}; + + EXPECT_EQ(tc.expected, s.twoSum(tc.nums, tc.target)); +} + +TEST(TwoSum, Case4) { + TestCase tc = {.nums{3, 3}, .target{0}, .expected{-1, -1}}; + Solution s{}; + + EXPECT_EQ(tc.expected, s.twoSum(tc.nums, tc.target)); +} \ No newline at end of file From 94e8d78d5fffecdbfa76807d94bdaa2a674443fe Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Thu, 29 Jan 2026 11:09:08 +0700 Subject: [PATCH 2/6] LC Median Of Two Sorted Arrays --- CMakeLists.txt | 2 + .../MedianTwoSortedArrays.cpp | 37 +++++++++++++++++++ .../median_two_arrays/MedianTwoSortedArrays.h | 31 ++++++++++++++++ tests/median_two_sorted_arrays.cpp | 22 +++++++++++ 4 files changed, 92 insertions(+) create mode 100644 src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp create mode 100644 src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.h create mode 100644 tests/median_two_sorted_arrays.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7edc23c..988087a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,12 +127,14 @@ set(APP_SOURCES "src/core/expression/Lambda.cpp" "src/core/expression/FunctionPointer.cpp" "src/leetcode/arrays/two_sum/TwoSum.cpp" + "src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp" ) # Test files set(APP_TESTS "tests/DeleteMeTest.cpp" "tests/two_sum_unittest.cpp" + "tests/median_two_sorted_arrays.cpp" ) # ---------------------------------------------------------------------------------------- diff --git a/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp b/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp new file mode 100644 index 0000000..becf558 --- /dev/null +++ b/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp @@ -0,0 +1,37 @@ +#include "MedianTwoSortedArrays.h" +#include + +/** + * Time Complexity: O((m+n) + (m+n)log(m+n)) ~ O((m+n)log(m+n)) + * Space Complexity: O(n+m) + */ +double Solution::findMedianSortedArrays(const std::vector& nums1, + const std::vector& nums2) { + std::vector nums{}; + nums.reserve( + nums1.size() + + nums2.size()); // should use reserve to pre-allocate the required mem + + nums.insert(nums.end(), nums1.begin(), + nums1.end()); // insert: copy n + m => O(m+n) + nums.insert(nums.end(), nums2.begin(), nums2.end()); + + std::sort(nums.begin(), nums.end()); // sort: NLogN => (m+n)Log(m+n) + + size_t size = nums.size(); + if (size == 0) { + return -1; + } + + if (size % 2 != 0) { + int index = + size / + 2; // integer division truncates toward zero, so size / 2 gives the lower middle index + return nums.at(index); + } else { + int index1 = size / 2; + int index2 = size / 2 - 1; + int sum = nums.at(index1) + nums.at(index2); + return sum / 2.0; + } +} \ No newline at end of file diff --git a/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.h b/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.h new file mode 100644 index 0000000..a595ca5 --- /dev/null +++ b/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.h @@ -0,0 +1,31 @@ + +#pragma once +// Hard + +// Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. +// The overall run time complexity should be O(log (m+n)). + +// Example 1: +// Input: nums1 = [1,3], nums2 = [2] +// Output: 2.00000 +// Explanation: merged array = [1,2,3] and median is 2. + +// Example 2: +// Input: nums1 = [1,2], nums2 = [3,4] +// Output: 2.50000 +// Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5. + +// Constraints: +// nums1.length == m +// nums2.length == n +// 0 <= m <= 1000 +// 0 <= n <= 1000 +// 1 <= m + n <= 2000 +// -106 <= nums1[i], nums2[i] <= 106 + +#include +class Solution { + public: + double findMedianSortedArrays(const std::vector& nums1, + const std::vector& nums2); +}; \ No newline at end of file diff --git a/tests/median_two_sorted_arrays.cpp b/tests/median_two_sorted_arrays.cpp new file mode 100644 index 0000000..25378e6 --- /dev/null +++ b/tests/median_two_sorted_arrays.cpp @@ -0,0 +1,22 @@ +#include +#include "../src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.h" + +TEST(MedianTwoSortedArrays, Case1) { + std::vector nums1{1, 2}; + std::vector nums2{3}; + double expected{2.0}; + + Solution s{}; + + EXPECT_EQ(expected, s.findMedianSortedArrays(nums1, nums2)); +} + +TEST(MedianTwoSortedArrays, Case2) { + std::vector nums1{1, 2}; + std::vector nums2{3, 3}; + double expected{2.5}; + + Solution s{}; + + EXPECT_EQ(expected, s.findMedianSortedArrays(nums1, nums2)); +} \ No newline at end of file From 9d5e300887d7485d47c2741d0dd28c2984f439b5 Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Thu, 29 Jan 2026 11:18:31 +0700 Subject: [PATCH 3/6] update name ut --- CMakeLists.txt | 4 ++-- ..._sorted_arrays.cpp => median_two_sorted_arrays_ut.cpp} | 4 ++-- tests/{two_sum_unittest.cpp => two_sum_ut.cpp} | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) rename tests/{median_two_sorted_arrays.cpp => median_two_sorted_arrays_ut.cpp} (85%) rename tests/{two_sum_unittest.cpp => two_sum_ut.cpp} (89%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 988087a..fca5a0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,8 +133,8 @@ set(APP_SOURCES # Test files set(APP_TESTS "tests/DeleteMeTest.cpp" - "tests/two_sum_unittest.cpp" - "tests/median_two_sorted_arrays.cpp" + "tests/two_sum_ut.cpp" + "tests/median_two_sorted_arrays_ut.cpp" ) # ---------------------------------------------------------------------------------------- diff --git a/tests/median_two_sorted_arrays.cpp b/tests/median_two_sorted_arrays_ut.cpp similarity index 85% rename from tests/median_two_sorted_arrays.cpp rename to tests/median_two_sorted_arrays_ut.cpp index 25378e6..0518e5b 100644 --- a/tests/median_two_sorted_arrays.cpp +++ b/tests/median_two_sorted_arrays_ut.cpp @@ -1,7 +1,7 @@ #include #include "../src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.h" -TEST(MedianTwoSortedArrays, Case1) { +TEST(MedianTwoSortedArrays, TC1) { std::vector nums1{1, 2}; std::vector nums2{3}; double expected{2.0}; @@ -11,7 +11,7 @@ TEST(MedianTwoSortedArrays, Case1) { EXPECT_EQ(expected, s.findMedianSortedArrays(nums1, nums2)); } -TEST(MedianTwoSortedArrays, Case2) { +TEST(MedianTwoSortedArrays, TC2) { std::vector nums1{1, 2}; std::vector nums2{3, 3}; double expected{2.5}; diff --git a/tests/two_sum_unittest.cpp b/tests/two_sum_ut.cpp similarity index 89% rename from tests/two_sum_unittest.cpp rename to tests/two_sum_ut.cpp index eabfb41..aee0d17 100644 --- a/tests/two_sum_unittest.cpp +++ b/tests/two_sum_ut.cpp @@ -7,28 +7,28 @@ struct TestCase { std::vector expected; }; -TEST(TwoSum, Case1) { +TEST(TwoSum, TC1) { TestCase tc = {.nums{2, 7, 11, 15}, .target{9}, .expected{0, 1}}; Solution s{}; EXPECT_EQ(tc.expected, s.twoSum(tc.nums, tc.target)); } -TEST(TwoSum, Case2) { +TEST(TwoSum, TC2) { TestCase tc = {.nums{3, 2, 4}, .target{6}, .expected{1, 2}}; Solution s{}; EXPECT_EQ(tc.expected, s.twoSum(tc.nums, tc.target)); } -TEST(TwoSum, Case3) { +TEST(TwoSum, TC3) { TestCase tc = {.nums{3, 3}, .target{6}, .expected{0, 1}}; Solution s{}; EXPECT_EQ(tc.expected, s.twoSum(tc.nums, tc.target)); } -TEST(TwoSum, Case4) { +TEST(TwoSum, TC4) { TestCase tc = {.nums{3, 3}, .target{0}, .expected{-1, -1}}; Solution s{}; From cb30fc51714d443c7f38055d960c3b5764a31e53 Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Thu, 29 Jan 2026 16:50:49 +0700 Subject: [PATCH 4/6] add stream/file io examples --- CMakeLists.txt | 6 ++ src/core/filehandle/FileIO.cpp | 113 +++++++++++++++++++++++++++ src/core/filehandle/IOStream.cpp | 35 +++++++++ src/core/filehandle/StringStream.cpp | 41 ++++++++++ 4 files changed, 195 insertions(+) create mode 100644 src/core/filehandle/FileIO.cpp create mode 100644 src/core/filehandle/IOStream.cpp create mode 100644 src/core/filehandle/StringStream.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fca5a0b..102dd43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,6 +120,10 @@ set(APP_SOURCES "src/patterns/creational/AbstractFactory.cpp" "src/patterns/creational/Builder.cpp" "src/patterns/creational/Prototype.cpp" + ## Streams + "src/core/filehandle/IOStream.cpp" + "src/core/filehandle/StringStream.cpp" + "src/core/filehandle/FileIO.cpp" ## Container "src/core/datatypes/container/sequence/Array.cpp" "src/core/datatypes/container/sequence/Vector.cpp" @@ -128,6 +132,7 @@ set(APP_SOURCES "src/core/expression/FunctionPointer.cpp" "src/leetcode/arrays/two_sum/TwoSum.cpp" "src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp" + "src/leetcode/arrays/container_with_most_water/ContainerWithMostWater.cpp" ) # Test files @@ -135,6 +140,7 @@ set(APP_TESTS "tests/DeleteMeTest.cpp" "tests/two_sum_ut.cpp" "tests/median_two_sorted_arrays_ut.cpp" + "tests/container_with_most_water_ut.cpp" ) # ---------------------------------------------------------------------------------------- diff --git a/src/core/filehandle/FileIO.cpp b/src/core/filehandle/FileIO.cpp new file mode 100644 index 0000000..9039640 --- /dev/null +++ b/src/core/filehandle/FileIO.cpp @@ -0,0 +1,113 @@ +#include +#include + +namespace { + +constexpr inline std::string_view test_file_name = "fileio_test.csv"; + +void fileInput() { + std::ifstream inFile{std::string{test_file_name}}; + if (!inFile.is_open()) { + std::cerr << "Cannot open file: " << test_file_name << " \n"; + } + + std::string inputStr{}; + std::cout << "====skip while space content====" << std::endl; + while ( + inFile >> + inputStr) { // Note that ifstream returns a 0 if we’ve reached the end of the file (EOF) + std::cout << inputStr; + } + std::cout << "========" << std::endl; + std::cout << "====full content====" << std::endl; + + // not skip whitespace + inFile.close(); + inFile.open(std::string{test_file_name}); // explicitly call open() + // The otherway to do this + /** + * inFile.clear(); // clear eof/fail flags + * inFile.seekg(0); // rewind + */ + + inputStr.clear(); + while (std::getline(inFile, inputStr)) { + std::cout << inputStr << std::endl; + } + std::cout << "========" << std::endl; + + inFile.close(); +} + +void fileOutput() { + std::ofstream outfile{std::string{ + test_file_name}}; // only output stream creates new file if not exist + if (!outfile || !outfile.is_open()) { + std::cerr << "Cannot open file: " << test_file_name << " \n"; + return; + } + + // Put bytes data to the file + // put string + std::string elfBytes{ + R"""( + time_s, + gsr_value 0.0, 45.27761157741693 0.005, 41.69912812397066 0.01, + 38.13110177547114 0.015, 35.32162785580394 0.02, + 31.75617843363382 0.025, 28.352875321528607 0.03, + 25.23210282654006 0.035, 21.769688905641132 0.04, + 17.99031153059391 0.045, 15.073732055666543 0.05, + 15.13550182371759 0.055, 14.69547985289048 0.06, + 14.867397107985468 0.065, 14.982082556093832 0.07, + 14.893751010484861 0.075, 14.877034044202343 0.08, + 14.820590581790071 0.085, 15.1065350504897 0.09, + 15.152287796727098 0.095, 14.764395300078201 0.1, + 15.118189654760348 0.105, 15.473255351586635 0.11, + 14.913896402347113 + \n )"""}; + outfile << elfBytes; + + elfBytes = + "0x0 0x0" + "0x0 0x0" + "0x0 0x0"; + outfile << elfBytes; + + elfBytes = + "0xF 0xA \ + 0xE 0xB \ + 0x0 0x0"; + outfile << elfBytes; + + outfile.put('E'); // put char + outfile.close(); +} + +void fileRemove() { + std::remove(std::string{test_file_name}.c_str()); + std::ifstream ifile{std::string{test_file_name}}; + if (ifile) { + std::cerr << "Cannot delete file: " << test_file_name << " \n"; + return; + } + + std::cout << "Delete file: " << test_file_name << " \n"; +} + +void run() { + // Create and produce data to a file + fileOutput(); + + // Load the created file as input and display its content + fileInput(); + + // remove the file + fileRemove(); +} +} // namespace + +struct FileIO { + FileIO() { run(); } +}; + +static FileIO autoRunner; \ No newline at end of file diff --git a/src/core/filehandle/IOStream.cpp b/src/core/filehandle/IOStream.cpp new file mode 100644 index 0000000..d455a69 --- /dev/null +++ b/src/core/filehandle/IOStream.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +namespace { +void run() { + std::cout << "\n--- IO Streams Example ---\n"; + // 1) input stream + + // input source using std::stringstream + std::string inputStr{}; + std::stringstream input("input aa aa"); + + // save and redirect std::cin + auto* oldBuf = std::cin.rdbuf(input.rdbuf()); + + // input from keyboard, + // std::cin >> inputStr; // skip whitespace + std::getline(std::cin, inputStr); // get all + + // have to restore std::cin + std::cin.rdbuf(oldBuf); + + // 2) output stream + std::cout << "[cout] " << inputStr << '\n'; + std::cerr << "[cerr] " << inputStr << '\n'; // unbuffered + std::clog << "[clog] " << inputStr << '\n'; // buffered +} +} // namespace + +struct IOStreamRunner { + IOStreamRunner() { run(); } +}; + +static IOStreamRunner autoRunner; \ No newline at end of file diff --git a/src/core/filehandle/StringStream.cpp b/src/core/filehandle/StringStream.cpp new file mode 100644 index 0000000..e435a49 --- /dev/null +++ b/src/core/filehandle/StringStream.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +namespace { +void run() { + std::cout << "\n--- String Stream Example ---\n"; + + std::stringstream os{}; + + // input + os << "0xF"; + std::cout << os.str(); + + // Note: After changing .str(), always call .clear() before reading. + os.str("0x1 0x2"); + os.clear(); + std::cout << os.str(); + + // output + std::string bytesStr = os.str(); + std::cout << bytesStr; + + os.str("0x0 0xF 0xE 0x2"); + os.clear(); + os >> bytesStr; + std::cout << bytesStr; + + // conversions + int byte_low = 0xFFF; + int byte_high = 0x001; + os.clear(); + os << byte_low << ' ' << byte_high; + std::cout << os.str(); +} +} // namespace + +struct StringStreamRunner { + StringStreamRunner() { run(); } +}; + +static StringStreamRunner autoRunner; \ No newline at end of file From 0393b04928d22eddfbca1030d6c52702f22fbe5a Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Fri, 30 Jan 2026 10:06:27 +0700 Subject: [PATCH 5/6] Update class name --- .../arrays/median_two_arrays/MedianTwoSortedArrays.cpp | 4 ++-- src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.h | 3 ++- tests/median_two_sorted_arrays_ut.cpp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp b/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp index becf558..ffbe271 100644 --- a/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp +++ b/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp @@ -5,8 +5,8 @@ * Time Complexity: O((m+n) + (m+n)log(m+n)) ~ O((m+n)log(m+n)) * Space Complexity: O(n+m) */ -double Solution::findMedianSortedArrays(const std::vector& nums1, - const std::vector& nums2) { +double MedianTwoSortedArrays::findMedianSortedArrays( + const std::vector& nums1, const std::vector& nums2) { std::vector nums{}; nums.reserve( nums1.size() + diff --git a/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.h b/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.h index a595ca5..d532e48 100644 --- a/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.h +++ b/src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.h @@ -1,4 +1,5 @@ +//cppcheck-suppress-file [functionStatic] #pragma once // Hard @@ -24,7 +25,7 @@ // -106 <= nums1[i], nums2[i] <= 106 #include -class Solution { +class MedianTwoSortedArrays { public: double findMedianSortedArrays(const std::vector& nums1, const std::vector& nums2); diff --git a/tests/median_two_sorted_arrays_ut.cpp b/tests/median_two_sorted_arrays_ut.cpp index 0518e5b..f95d7ec 100644 --- a/tests/median_two_sorted_arrays_ut.cpp +++ b/tests/median_two_sorted_arrays_ut.cpp @@ -6,7 +6,7 @@ TEST(MedianTwoSortedArrays, TC1) { std::vector nums2{3}; double expected{2.0}; - Solution s{}; + MedianTwoSortedArrays s{}; EXPECT_EQ(expected, s.findMedianSortedArrays(nums1, nums2)); } @@ -16,7 +16,7 @@ TEST(MedianTwoSortedArrays, TC2) { std::vector nums2{3, 3}; double expected{2.5}; - Solution s{}; + MedianTwoSortedArrays s{}; EXPECT_EQ(expected, s.findMedianSortedArrays(nums1, nums2)); } \ No newline at end of file From 6b150c92672aca21faf4b9ca59ac98a953c266d8 Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Fri, 30 Jan 2026 12:31:23 +0700 Subject: [PATCH 6/6] fix build issue --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 102dd43..431cd52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,7 +132,7 @@ set(APP_SOURCES "src/core/expression/FunctionPointer.cpp" "src/leetcode/arrays/two_sum/TwoSum.cpp" "src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp" - "src/leetcode/arrays/container_with_most_water/ContainerWithMostWater.cpp" + # "src/leetcode/arrays/container_with_most_water/ContainerWithMostWater.cpp" ) # Test files @@ -140,7 +140,7 @@ set(APP_TESTS "tests/DeleteMeTest.cpp" "tests/two_sum_ut.cpp" "tests/median_two_sorted_arrays_ut.cpp" - "tests/container_with_most_water_ut.cpp" + # "tests/container_with_most_water_ut.cpp" ) # ----------------------------------------------------------------------------------------