일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- machine learning
- nginx
- var
- scss
- vue.js
- Python
- npm
- JavaScript
- BOJ
- property
- Clone
- vuetify
- docker
- dotenv
- loop
- VUE
- 보안
- webpack
- 앙상블
- leetcode
- C++
- generic
- type
- condition
- bash
- C#
- TypeScript
- AI
- git
- security
Archives
- Today
- Total
ice rabbit programming
[LeetCode] Remove Element 본문
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;
}
}
'PS > LeetCode' 카테고리의 다른 글
[LeetCode] Valid Parenthese (0) | 2020.04.15 |
---|---|
[LeetCode] Longest Common Prefix (0) | 2020.04.15 |
[LeetCode] Remove Duplicates From Sorted Array (0) | 2020.04.15 |
[LeetCode] 9. Palindrome Number (0) | 2020.04.12 |
[LeetCode] 7. Reverse Integer (0) | 2020.04.12 |