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