본문 바로가기
알고리즘

[Algorithm & English Study] LeetCode 27. Remove Element

by 내가 진짜 유일한 2024. 11. 23.

English Content

Given an integer array nums and an integer val, remove all occurrences of val in nums in-place.

The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.

Consider the number of elements in nums which are not equal to val be k, to get accepted,

you need to do the following things:

  • Change the array nums such that the first k elements of nums contain the elements which are not equal to val. The remaining elements of nums are not important as well as the size of nums.
  • return k

내가 번역한 내용

정수형 배열 nums와 정수 val을 주어주고, nums의 in-place인 val의 모든 occurrences를 제거한다.

요소들의 순서는 변경될 수 있다. nums 배열에 있는 요소들의 개수가 반환되고, val과 일치하지 않는다.

nums 배열에 있는 요소들의 개수를 고려해라, val be k가 일치하지 않는 것을, get accepted 하기 위해,

너는 다음과 같은 것을 지켜야한다.

nums 배열에서 nums 배열의 첫 k 번째 요소들이 val에 일치하지않는 그 요소들을 contain하는 것을 교체해라

remaining한 nums 배열의 요소들은 nums의 크기 만큼 중요하지 않다

k를 반환해라

 

영어 문장(단어) 맥락으로 뜻 추측 단어 해석 단어가 포함된 문장
in-place 그 위치에~ 제자리에, 결정된 곳에, 올바른 곳에 remove all occurrences of val in nums in-place
occurrences 관련있는 것 발생, 일어난 일 remove all occurrences of val in nums in-place
be not equal to val be k val와 k가 일치하지 않도록 ~와 동일하지 않다 which are not equal to val
get accepted 받아들이다 합격하다, 수락되다 which are not equal to val be k, to get accepted
remaining 다시 중요한 것은 남은, 남다 The remaining elements of nums are not important as well as the size of nums
contain 요소, 내용 포함하다, 담고 있다 the first k elements of nums contain the elements
a number of 한 수 많은 -
The number of 그 수 Then return the number of elements in nums which are not equal to val
such ~ 와 비슷한, 같은 이러한, ~와 같은 Change the array nums such that the first k elements of nums contain the elements which are not equal to val

단어를 알고 난 후, 해석한 내용

정수형 배열 nums와 정수 val을 주고, nums 배열 자리에 val의 발생을 모두 제거한다.

요소들의 순서는 변경 될 것이다. 그러고 nums 배열에 val과 일치하지 않은 요소들의 수가 반환된다.

nums 배열안에 val과 k가 같지 않은 요소의 수를 고려해라.

합격하기 위해 너는 다음 과 같은 것을 지켜야한다.

nums 배열과 같은 nums 배열의 첫 번째 k 번 요소를 포함하는 요소들, val과 동일하지 않게 변경해라.

nums 배열의 남아있는 요소들이 nums의 크기 만큼 중요하지 않다.

k를 반환해라.

번역기 영어 해석 내용

정수 배열 nums와 정수 val이 주어지면 nums에서 val의 모든 발생을 그 자리에서 제거합니다.

요소의 순서는 변경될 수 있습니다. 그런 다음 val과 같지 않은 nums의 요소 수를 반환합니다.

val과 같지 않은 nums의 요소 수를 k라고 가정하면 수락되려면

다음 작업을 수행해야 합니다.

  • nums의 처음 k개 요소에 val과 같지 않은 요소가 포함되도록 nums 배열을 변경합니다. nums의 나머지 요소와 nums의 크기는 중요하지 않습니다.
  • k를 반환합니다.

문제 풀이 코드

class Solution(object):
    def removeElement(self, nums, val):
        for i in range(nums.count(val)):
            nums.remove(val)

        k = len(nums)
        return k