We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
原题链接
gi++ sj++ res++
sj++
将需求因子 g 和 s 分别从小到大进行排序,使用贪心思想,配合双指针,每个饼干只尝试一次,成功则换下一个孩子来尝试。
const findContentChildren = function (g, s) { g = g.sort((a, b) => a - b) s = s.sort((a, b) => a - b) let gi = 0 // 胃口值 let sj = 0 // 饼干尺寸 let res = 0 while (gi < g.length && sj < s.length) { if (s[sj] >= g[gi]) { gi++ sj++ res++ } else { sj++ } } return res }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接
贪心算法+双指针
gi++ sj++ res++
。sj++
。关键点
将需求因子 g 和 s 分别从小到大进行排序,使用贪心思想,配合双指针,每个饼干只尝试一次,成功则换下一个孩子来尝试。
The text was updated successfully, but these errors were encountered: