Published:
Updated:

  • Reference
  • ์‹œ๊ฐ„๋ณต์žก๋„: $O(N^2)$
    • extend -> $O(N)$
  • Runtime 63ms
  • Beats 88.97%
  • ์ด์ œ๋ถ€ํ„ฐ ๋ฆฟ์ฝ”๋“œ๋Š” ์ž์ฒด ide๋กœ ํ’€์–ด๋‚˜๊ฐˆ ์ƒ๊ฐ์ž„


Solution

class Solution:
    # ๋ฐฐ์—ด์— val์„ freq๋ฒˆ extend ํ•ด์ฃผ์ž
    # ๊ทธ ํ›„ ๋‘ ๋ฐฐ์—ด์„ ๋”ํ•˜๊ณ  concatenation์— ์ €์žฅํ•˜๋ฉด ๋
    def decompressRLElist(self, nums: List[int]) -> List[int]:
        concatenation = []

        # +2์”ฉ ๋ฐ˜๋ณต๋จ
        for i in range (0, len(nums), +2):
            freq = nums[i]
            val = nums[i + 1]

            # append: ๋ฆฌ์ŠคํŠธ ๊ทธ ์ž์ฒด๋ฅผ ๋์— ๋„ฃ์Œ
            # extend: ๋ฆฌ์ŠคํŠธ ๊ฐ๊ฐ์˜ ์š”์†Œ๋“ค์„ ๋์—๋‹ค ํ•˜๋‚˜์”ฉ ๋„ฃ์Œ
            concatenation.extend([val] * freq)

        return concatenation

Leave a comment