初始化代码库

This commit is contained in:
Yaha 2023-05-17 22:54:41 +08:00
parent bb23537af0
commit 4a8dbeffa5
4 changed files with 100 additions and 0 deletions

2
.gitignore vendored
View File

@ -32,3 +32,5 @@
*.out *.out
*.app *.app
.idea/
cmake-build-debug/

37
CMakeLists.txt Normal file
View File

@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.25)
project(leetcode)
set(CMAKE_CXX_STANDARD 17)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
include(GoogleTest)
set(SOURCES)
file(GLOB_RECURSE SOURCES "src/*/*.cpp")
enable_testing()
# Iterate over each source file
message(STATUS "========= enable_testing ========")
foreach(SOURCE ${SOURCES})
# Get the file name without extension
get_filename_component(APP_NAME ${SOURCE} NAME_WE)
message(STATUS "==== app_name: ${APP_NAME} path: ${SOURCE}")
# Add an executable target for each file
add_executable(${APP_NAME} ${SOURCE})
target_link_libraries(
${APP_NAME}
GTest::gtest_main
)
gtest_discover_tests(${APP_NAME})
endforeach()
message(STATUS "========= end testing ========")

6
main.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}

55
src/map/two_sum.cpp Normal file
View File

@ -0,0 +1,55 @@
//
// Created by Yaha on 2023/5/17.
//
#include <iostream>
#include <map>
#include <gtest/gtest.h>
/*
1
nums = [2,7,11,15], target = 9
[0,1]
nums[0] + nums[1] == 9 [0, 1]
2
nums = [3,2,4], target = 6
[1,2]
3
nums = [3,3], target = 6
[0,1]
 
2 <= nums.length <= 104
-109 <= nums[i] <= 109
-109 <= target <= 109
LeetCode
https://leetcode.cn/problems/two-sum
*/
/**
* @param nums
* @param target
* @return
*/
std::vector<int> twoSum(std::vector<int>& nums, int target) {
std::map<int, int> m;
for (int i = 0; i < nums.size(); ++i) {
if (target - nums[i] == 0) {
}
}
}
TEST(TwoSumTest, BasicAssertions) {
auto a = twoSum(std::vector<int>{2,7,11,15}, 9);
}