Development/Algorithm
[LeetCode] Remove Duplicates from Sorted Array
동스토리
2021. 8. 22. 13:35
반응형
안녕하세요.
LeetCode 26번 Remove Duplicates from Sorted Array 문제풀이 하겠습니다.
https://leetcode.com/problems/remove-duplicates-from-sorted-array/
Remove Duplicates from Sorted Array - 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
[문제]
[TestCase]
[해설]
해당 문제는 리스트에서 중복되는 문자열이 있으면 리스트에서 제거해주고 최종 리스트의 길이를 출력해주면 됩니다.
[코드]
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
for num in nums:
while nums.count(num) > 1:
nums.remove(num)
return(len(nums))
감사합니다.
반응형