From fb555eb2cc5d0c7bef9ef41f12d43e9e53c2fd02 Mon Sep 17 00:00:00 2001 From: caixiangyue Date: Mon, 28 Aug 2023 16:15:56 +0800 Subject: [PATCH] add 19 --- 0019.h | 28 ++++++++++++++++++++++++++++ CMakeLists.txt | 14 +++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 0019.h diff --git a/0019.h b/0019.h new file mode 100644 index 0000000..c956108 --- /dev/null +++ b/0019.h @@ -0,0 +1,28 @@ +#include "common.h" + +namespace s0019 { + // Definition for singly-linked list. + struct ListNode { + int val; + ListNode *next; + ListNode() : val(0), next(nullptr) {} + ListNode(int x) : val(x), next(nullptr) {} + ListNode(int x, ListNode *next) : val(x), next(next) {} + }; + class Solution { + public: + ListNode* removeNthFromEnd(ListNode* head, int n) { + ListNode *dummyHead = new ListNode(0, head); + ListNode *slow = dummyHead, *fast = dummyHead; + while (n--) fast = fast->next; + fast = fast->next; + while (fast) { + fast = fast->next; + slow = slow->next; + } + slow->next = slow->next->next; + + return dummyHead->next; + } + }; +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8206a0b..dd82cbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,18 +8,18 @@ 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( +# 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) +FetchContent_MakeAvailable(googletest) # add the executable add_executable(${PROJECT_NAME} ${src_list}) @@ -29,6 +29,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC ) target_link_libraries(${PROJECT_NAME} PRIVATE - fmt::fmt + #fmt::fmt gtest_main ) \ No newline at end of file