parent
eded252643
commit
b4699c3bac
|
|
@ -123,6 +123,22 @@ public:
|
|||
|
||||
|
||||
Java:
|
||||
```java
|
||||
class Solution {
|
||||
public int removeElement(int[] nums, int val) {
|
||||
// 快慢指针
|
||||
int fastIndex = 0;
|
||||
int slowIndex;
|
||||
for (slowIndex = 0; fastIndex < nums.length; fastIndex++) {
|
||||
if (nums[fastIndex] != val) {
|
||||
nums[slowIndex] = nums[fastIndex];
|
||||
slowIndex++;
|
||||
}
|
||||
}
|
||||
return slowIndex;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Python:
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue