add cpp solution of lc 27

pull/18/head
xuxuxu 2021-04-26 07:06:31 -07:00
parent 690f7a4be2
commit 4a942ae0d6
1 changed files with 44 additions and 0 deletions

View File

@ -50,6 +50,8 @@
****
Java Code:
```java
class Solution {
public int removeElement(int[] nums, int val) {
@ -74,6 +76,28 @@ class Solution {
}
}
```
C++ Code:
```c++
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int len=nums.size();
if(len==0)
return len;
int i=0;
for(;i<len;++i){
if(nums[i]==val){
for(int j=i;j<len-1;++j){
nums[j]=nums[j+1];
}
--i;
--len;
}
}
return len;
}
};
```
****
@ -108,6 +132,26 @@ class Solution {
}
```
C++ Code:
```c++
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int len=nums.size();
if(len==0)
return len;
int i=0;
for(int j=0;j<len;++j){
if(nums[j]==val)
continue;
else
nums[i++]=nums[j];
}
return i;
}
};
```
Python3 Code:
```py