Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ add_executable(main "${SRC_DIR}/main.cpp" "${SRC_DIR}/two-sum.cpp")

find_package(GTest REQUIRED)
add_executable(two-sum-test "${TEST_DIR}/test.cpp" "${SRC_DIR}/two-sum.cpp")
target_link_libraries(two-sum-test PRIVATE gtest::gtest)
target_link_libraries(two-sum-test PRIVATE GTest::GTest GTest::Main)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем потребовалось изменение? Не компилировалось?

Copy link
Copy Markdown
Author

@jonyks jonyks Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Верно, вызывалась ошибка указывающая на неправильную строку кода
Без имени2

target_compile_options(two-sum-test PRIVATE "-fsanitize=address,undefined")
target_link_options(two-sum-test PRIVATE "-fsanitize=address,undefined")
add_test(NAME two-sum-test COMMAND two-sum-test)
Expand Down
15 changes: 15 additions & 0 deletions src/two-sum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "two-sum.hpp"
#include <cstddef> // Добавьте эту строку

bool two_sum(const int nums[ARRAY_SIZE], const int target, std::size_t& index0, std::size_t& index1) {
for (std::size_t i = 0; i < ARRAY_SIZE; ++i) {
for (std::size_t j = i + 1; j < ARRAY_SIZE; ++j) {
if (nums[i] + nums[j] == target) {
index0 = i;
index1 = j;
return true;
}
}
}
return false;
}