commit ca629b1719f6f4cdae1dd937fae3c54bbd359b7c
parent 0a7268c1e98e137356cddba07e60066682e59aa6
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date: Mon, 10 Apr 2023 10:20:42 -0500
Completed problem to remove elements of given value from vector
Diffstat:
2 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/remove-element/a.out b/remove-element/a.out
Binary files differ.
diff --git a/remove-element/remove-element.cpp b/remove-element/remove-element.cpp
@@ -0,0 +1,40 @@
+#include <iostream>
+#include <vector>
+using namespace std;
+
+//Leet Ratings
+// Speed Memory
+//Total 0ms 8.9MB
+//Beats 100% 47.58%
+//
+
+
+//This question is terrible!
+//This is basically just a side effect where you need
+//to update the vector and return the number of good
+//values in it.
+
+
+int removeElement(vector<int>& nums, int val) {
+ int count = 0;
+ vector<int> num;
+ for(int i = 0 ; i < nums.size() ; ++i){
+ if(nums[i] != val){
+ num.push_back(nums[i]);
+ count += 1;
+ }
+ }
+ nums = num;
+ return count;
+}
+
+
+int main(){
+ vector <int> vec = {0, 1, 2, 3, 4, 5, 6,6,6,5,4};
+ removeElement(vec , 4);
+ for(int i = 0 ; i < vec.size(); ++i){
+ cout << vec[i] << " ";
+ }
+ cout << endl;
+
+}