Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
caixiangyue committed Aug 19, 2023
0 parents commit e2ecbff
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/build/_deps/fmt-src/include",
"${workspaceFolder}/build/_deps/googletest-src/googletest/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
73 changes: 73 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"files.associations": {
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
}
}
20 changes: 20 additions & 0 deletions 0001.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "common.h"

using namespace std;
namespace s0001 {
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> m;
for (int i=0; i<nums.size(); i++){
int tmp = target - nums[i];
auto iter = m.find(tmp);
if (iter == m.end())
m[nums[i]] = i;
else
return {iter->second, i};
}
return {-1, -1};
}
};
}
34 changes: 34 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.14)

# set the project name
project(test VERSION 1.0.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(src_list test.cc)
include(FetchContent)

FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG master
)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main
)

FetchContent_MakeAvailable(fmt googletest)

# add the executable
add_executable(${PROJECT_NAME} ${src_list})

target_include_directories(${PROJECT_NAME} PUBLIC
${PROJECT_BINARY_DIR}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
fmt::fmt
gtest_main
)
2 changes: 2 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <vector>
#include <unordered_map>
10 changes: 10 additions & 0 deletions test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "0001.h"
#include <gtest/gtest.h>


TEST(S001, Normal) {
s0001::Solution s;
std::vector<int> v = {1,2,3};
// std::vector<int> r = {0,1};
EXPECT_EQ(std::vector<int>({0,1}), s.twoSum(v, 3));
}

0 comments on commit e2ecbff

Please sign in to comment.