Merge pull request #2792 from ch4r1ty/master

更新了0027.移除元素.md,增加了java暴力法
This commit is contained in:
程序员Carl
2024-11-16 17:49:01 +08:00
committed by GitHub

View File

@ -131,7 +131,24 @@ public:
## 其他语言版本 ## 其他语言版本
### Java ### 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 ```java
class Solution { class Solution {
public int removeElement(int[] nums, int val) { public int removeElement(int[] nums, int val) {