diff --git a/83/83. shadowing.md b/83/83. shadowing.md new file mode 100644 index 0000000..0a0a0ca --- /dev/null +++ b/83/83. shadowing.md @@ -0,0 +1,32 @@ +# # [83] (https://leetcode.com/problems/remove-duplicates-from-sorted-list/) +# C++ + +```cpp +#include + +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* deleteDuplicates(ListNode* head) { + ListNode* node = head; + + while (node != nullptr && node->next != nullptr) { + if (node->val == node->next->val) { + node->next = node->next->next; + } + else { + node = node->next; + } + } + return head; + } + +}; +```