更新了0027.移除元素.md,增加了java暴力法

This commit is contained in:
ch4r1ty
2024-10-16 00:01:58 -04:00
committed by GitHub
parent 371cfe182a
commit cb50b956eb

View File

@ -131,7 +131,24 @@ public:
## 其他语言版本
### Java
```java
class Solution {
public int removeElement(int[] nums, int val) {
// 暴力法
int n = nums.length;
for (int i = 0; i < n; i++) {
if (nums[i] == val) {
for (int j = i + 1; j < n; j++) {
nums[j - 1] = nums[j];
}
i--;
n--;
}
}
return n;
}
}
```
```java
class Solution {
public int removeElement(int[] nums, int val) {