-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e2ecbff
Showing
7 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include <vector> | ||
#include <unordered_map> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |