반응형

안녕하세요.

 

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))

 

 

감사합니다.

반응형

'Development > Algorithm' 카테고리의 다른 글

[LeetCode] Implement strStr()  (0) 2021.08.26
[LeetCode] Remove Element  (0) 2021.08.24
[LeetCode] Merge Two Sorted Lists  (0) 2021.08.17
[LeetCode] Roman to Integer  (0) 2021.08.08
[LeetCode] Palindrome Number  (0) 2021.08.07