[Leetcode] 27. Remove Element
[Leetcode] 27. Remove Element

[Leetcode] 27. Remove Element

์–ธ์–ด
Python
C
๋‚œ์ด๋„
๋‹ค์‹œ ํ’€์–ด๋ณด๊ธฐ
๋‹ค์‹œ ํ’€์–ด๋ณด๊ธฐ
์•Œ๊ณ ๋ฆฌ์ฆ˜ ์œ ํ˜•
์ž‘์„ฑ์ž
๋ฐ•์šฉ์„ฑ๋ฐ•์šฉ์„ฑ
์ƒ์„ฑ ์ผ์‹œ
2024๋…„ 09์›” 10์ผ
floatFirstTOC: right

๐Ÿ–ฅ๏ธย ์‹œ์ž‘ํ•˜๋ฉฐ

๊ฐ„๋‹จํ•˜๊ฒŒ ์ˆœํšŒํ•˜๋ฉด์„œ ๊ธฐ์กด์˜ ์š”์†Œ๋ฅผ ๋ฎ์–ด์”Œ์šฐ๋ฉด ๋œ๋‹ค.
ย 

โš™๏ธย Python

class Solution: def removeElement(self, nums: List[int], val: int) -> int: k = 0 # ์œ ์ง€ํ•  ์š”์†Œ์˜ ์ธ๋ฑ์Šค for i in range(len(nums)): if nums[i] != val: nums[k] = nums[i] k += 1 return k
ย 

๐Ÿ“Œย ์†Œ๊ฐ

๋Œ“๊ธ€

guest