Published:
Updated:

  • ๋ฌธ์ œ์— ์ •๋‹ต์ด ๊ฑฐ์˜ ๋‚˜์™€ ์žˆ์–ด์„œ ์ด์ง€์ธ ๋“ฏ


Solution

from typing import List


class Solution:
    def findContentChildren(self, g: List[int], s: List[int]) -> int:
        g.sort()
        s.sort()

        i, j = 0, 0
        while i < len(g) and j < len(s):
            # ๊ณผ์ž์˜ ํฌ๊ธฐ๊ฐ€ ์•„์ด์˜ ๋งŒ์กฑ๋„๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๋‹ค๋ฉด i ์ฆ๊ฐ€
            # ์ฆ‰, ๋งŒ์กฑ๋„๊ฐ€ ๊ฐ€์žฅ ๋‚ฎ์€ ์•„์ด์—๊ฒŒ ํฌ๊ธฐ๊ฐ€ ๊ฐ€์žฅ ์ž‘์€ ๊ณผ์ž๋ฅผ ์ฃผ๋Š” ๊ฒƒ
            if s[j] >= g[i]:
                i += 1

            # ๊ณผ์ž๋ฅผ ์–ด๋Š ์•„์ด์—๊ฒŒ ์ฃผ๋“  j๋Š” ๋ฌด์กฐ๊ฑด ์ฆ๊ฐ€
            j += 1

        return i


Reference

Leave a comment