Skip to content

Commit

Permalink
add 19
Browse files Browse the repository at this point in the history
  • Loading branch information
caixiangyue committed Aug 28, 2023
1 parent 75db6b9 commit fb555eb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
28 changes: 28 additions & 0 deletions 0019.h
Original file line number Diff line number Diff line change
@@ -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;
}
};
}
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -29,6 +29,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
fmt::fmt
#fmt::fmt
gtest_main
)

0 comments on commit fb555eb

Please sign in to comment.