mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 15:09:40 +08:00
更新了0027.移除元素.md,增加了java暴力法
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user