Today I Learned (2025-03-26)

SEONGJONG PARKSEONGJONG PARK
2 min read

[LeetCode]

[26. Remove Duplicates from Sorted Array]

  • Question Understanding

    • You need to work on the original array and modify it in-place.

    • You need to remove duplicates.

    • You need to return k, the number of unique elements.

    • Constraints

      • nums is sorted in non-decreasing order

      • nums not empty

class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        wr_idx = 1
        for idx in range(1, len(nums)):
            if nums[idx] != nums[idx - 1]:
                nums[wr_idx] = nums[idx]
                wr_idx += 1
        return wr_idx
  • Time & Space Complexity

    • Time: O(n)

    • Space: O(1) — in-place modification

[88. Merge Sorted Array]

  • Question Understanding

    • Merge two sorted arrays.

    • The trailing zeros in nums1 represent empty spaces to be filled.

    • nums1 has a total length of m + n, with the first m elements being valid.

    • nums2 has a length of n.

class Solution:
    def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
        for idx in range(m, len(nums1)):
            nums1[idx] = nums2[idx - m]
        nums1.sort()
  • Time & Space Complexity

    • Time: O((m + n) log(m + n))

    • Space: O(1) — in-place modification

[English]

[Word]

  • hence

    • Cause & Result) that is the reason or explanation for = therefore

    • Time Flow) from this time = starting now, or after a particular time

    • KR) (원인과 결과) 그래서, 그렇기때문에, 그러므로 / (시간형) 지금으로부터, 이후로

  • assert

    • Claiming something is true) to say that something is certainly true

    • Power behavior) to do something to show that you have power

    • In programming) to test if a condition is true — if not, it raises an error

    • KR) (주장) 강하게 주장하다, 단언하다, (권한행사) 권한/권력/영향력을 행사하다, 자신의 존재를 드러내다. (프로그래밍) 조건이 참인지 확인하고, 거짓이면 오류를 발생시킴

  • represent

  • trail

  • valid

  • corridor

  • freight

  • be filled by

  • be filled with

  • mine

  • environment

  • significant

  • have an impact on

  • relate to

  • topic

  • address

  • suffer

  • issue

  • work on

  • would you like to

[Sentence]

  • You need to work original array, modify in-place way.

    • work original array → work on the original array

      • "Work” is intransitive verb, so it needs to be used with “on”.
    • array, modify → array and modify

      • Do not connect two independent sentences with just a comma.
    • modify in-place way → modify it in-place.

      • Do not keep stacking nouns together unnatrually.

      • “in-place” is adverb. It describes the method of modification.

  • You need to return k, the unique elements number.

0
Subscribe to my newsletter

Read articles from SEONGJONG PARK directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

SEONGJONG PARK
SEONGJONG PARK