PS/LeetCode
[LeetCode] Remove Element
판교토끼
2020. 4. 15. 15:35
728x90
https://leetcode.com/problems/remove-element/
[
Remove Element - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
](https://leetcode.com/problems/remove-element/)
이전 문제와 비슷하게 반환 값만큼 input array를 검사한다. 다만 전 문제보다 조금 쉬운 듯? 그냥 제거한 만큼 앞으로 당겼다. 이 문제도 C#으로 풀었다.
// C#
public class Solution {
public int RemoveElement(int[] nums, int val) {
int count=0, result=0;
for(int i=0;i<nums.Length;i++) {
if(nums[i]==val) {
count++;
continue;
}
nums[i-count]=nums[i];
result++;
}
return result;
}
}
728x90