Go/Leet Code
[Go] Two-pointer Technique - Scenario II
Gopythor
2022. 4. 12. 22:34
728x90
반응형
Reconsider the Space Limitation
Java
public int removeElement(int[] nums, int val) {
int k = 0;
for (int i = 0; i < nums.length; ++i) {
if (nums[i] != val) {
nums[k] = nums[i];
k++;
}
}
return k;
}
Go
func removeElement(nums []int, val int) {
k := 0;
for i:=0; i < nums.length; i++{
if nums[i] != val{
nums[k] = nums[i]
k++
}
}
return k
}
728x90
반응형