diff --git a/leetcode-cc/DeleteNodeInLinkedList.hpp b/leetcode-cc/DeleteNodeInLinkedList.hpp new file mode 100644 index 0000000..4394a27 --- /dev/null +++ b/leetcode-cc/DeleteNodeInLinkedList.hpp @@ -0,0 +1,39 @@ +#include "TestHelper.h" +#include "problem.h" +#include "solution.h" + +using namespace std; + +IMPLEMENT_PROBLEM_CLASS( + PDeleteNodeInLinkedList, 237, DIFFI_MEDIUM, TOPIC_ALGORITHMS, + "Delete Node In Linked List", + "There is a singly-linked list head and we want to delete a node node in " + "it. You are given the node to be deleted node. You will not be given " + "access to the first node of head.", + {"Linked List"}); + +class SDeleteNodeInLinkedList : public ISolution { + public: + size_t problemId() const override { return 237; } + string name() const override { + return ("Solution for " + string("Delete Node In Linked List")); + } + string location() const override { return __FILE_NAME__; } + int test() const override { return 0; }; + int benchmark() const override { return 0; } + + private: + void deleteNode(ListNode* node) const { + if (node != nullptr) { + if (node->next) { + node->val = node->next->val; + + if (node->next->next) { + deleteNode(node->next); + } else { + node->next = nullptr; + } + } + } + } +}; diff --git a/leetcode-rs/src/lib.rs b/leetcode-rs/src/lib.rs index c6c5c88..6fbdf19 100644 --- a/leetcode-rs/src/lib.rs +++ b/leetcode-rs/src/lib.rs @@ -1,7 +1,5 @@ //! Collections of problems and solutions in LeetCode -#![feature(exclusive_range_pattern)] - mod btree; mod list; pub mod problems; diff --git a/runtime-cc/src/registration.cc b/runtime-cc/src/registration.cc index 2fdba64..5a77843 100644 --- a/runtime-cc/src/registration.cc +++ b/runtime-cc/src/registration.cc @@ -25,6 +25,7 @@ #include "../leetcode-cc/CourseSchedule.hpp" #include "../leetcode-cc/CourseScheduleII.hpp" #include "../leetcode-cc/DecodeWays.hpp" +#include "../leetcode-cc/DeleteNodeInLinkedList.hpp" #include "../leetcode-cc/DetIfTwoStrsAreClose.hpp" #include "../leetcode-cc/DeterIfStringHalvesAreAlike.hpp" #include "../leetcode-cc/DistinctSubsequences.hpp" @@ -966,5 +967,12 @@ const int registerAll(std::shared_ptr handle) { handle->registerSolution( []() -> ArcSolution { return std::make_shared(); }); + handle->registerProblem([]() -> ArcProblem { + return std::make_shared(); + }); + handle->registerSolution([]() -> ArcSolution { + return std::make_shared(); + }); + return 0; }