From a7ec631679c42f8c85a7285a61745db9dc524bba Mon Sep 17 00:00:00 2001 From: Jeongan Lee <84510455+fkdl0048@users.noreply.github.com> Date: Fri, 4 Oct 2024 23:07:07 +0900 Subject: [PATCH] Solve: Remove Element --- LeetCode/Remove Element.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 LeetCode/Remove Element.cpp diff --git a/LeetCode/Remove Element.cpp b/LeetCode/Remove Element.cpp new file mode 100644 index 0000000..54500fb --- /dev/null +++ b/LeetCode/Remove Element.cpp @@ -0,0 +1,14 @@ +class Solution { +public: + int removeElement(vector& nums, int val) { + int j = 0; + for (int i = 0; i < nums.size(); i++){ + if (nums[i] != val) { + nums[j] = nums[i]; + j++; + } + } + + return j; + } +}; \ No newline at end of file