• 문제 링크
Remove Element - LeetCode
Can you solve this real interview question? Remove Element - Given an integer array nums and an integer val, remove all occurrences of val in nums in-place [https://en.wikipedia.org/wiki/In-place_algorithm]. The order of the elements may be changed. Then r
leetcode.com
• 풀이 코드
public class Solution {
public int removeElement(int[] nums, int val) {
int idx = 0;
for (int i = 0; i < nums.length; i++) if (nums[i] != val) nums[idx++] = nums[i];
return idx;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 24. Swap Nodes in Pairs - Java (0) | 2026.05.17 |
|---|---|
| [LeetCode] 28. Find the Index of the First Occurrence in a String - Java (0) | 2026.05.16 |
| [LeetCode] 26. Remove Duplicates from Sorted Array - Java (0) | 2026.05.14 |
| [LeetCode] 21. Merge Two Sorted Lists - Java (0) | 2026.05.13 |
| [LeetCode] 20. Valid Parentheses - Java (0) | 2026.05.12 |
댓글