feat: 双指针

This commit is contained in:
wu xiangkai
2025-10-23 10:33:53 +08:00
parent d568671b85
commit 59f245dda7
4 changed files with 95 additions and 0 deletions

21
27.remove-element.java Normal file
View File

@@ -0,0 +1,21 @@
/*
* @lc app=leetcode id=27 lang=java
*
* [27] Remove Element
*/
// @lc code=start
class Solution {
public int removeElement(int[] nums, int val) {
int i = 0;
for(int j = 0; j < nums.length; j++) {
if(nums[j] != val) {
nums[i] = nums[j];
i++;
}
}
return i;
}
}
// @lc code=end