LeetCode20. 有效的括号
- 题目链接
- 代码
题目链接
https://leetcode.cn/problems/assign-cookies/
代码
从大遍历
class Solution:def findContentChildren(self, g: List[int], s: List[int]) -> int:g.sort()s.sort()index = len(s) - 1result = 0for i in range(len(g) - 1, -1, -1):if s[index] >= g[i] and index >= 0:result += 1index -= 1return result
从小遍历
class Solution:def findContentChildren(self, g: List[int], s: List[int]) -> int:g.sort()s.sort()index = 0for i in range(len(s)):if index < len(g) and g[index] <= s[i]:index += 1return index