{"id":117805,"date":"2026-10-25T14:08:17","date_gmt":"2026-10-25T06:08:17","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/117805.html"},"modified":"2026-10-25T14:08:17","modified_gmt":"2026-10-25T06:08:17","slug":"leetcode-c-1298-maximum-candies-you-can-get-from-boxes","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/117805.html","title":{"rendered":"LeetCode \/\/C - 1298. Maximum Candies You Can Get from Boxes"},"content":{"rendered":"<h3>1298. Maximum Candies You Can Get from Boxes<\/h3>\n<p>You have n boxes labeled from 0 to n &#8211; 1. You are given four arrays: status, candies, keys, and containedBoxes where:<\/p>\n<ul>\n<li>status[i] is 1 if the ith box is open and 0 if the <span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">\n<p>          i<\/p>\n<p>           t<\/p>\n<p>           h<\/p>\n<p>        i^{th}<\/p>\n<p>     <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.8491em\"><\/span><span class=\"mord\"><span class=\"mord mathnormal\">i<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.8491em\"><span class=\"\" style=\"top: -3.063em;margin-right: 0.05em\"><span class=\"pstrut\" style=\"height: 2.7em\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">t<\/span><span class=\"mord mathnormal mtight\">h<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span> box is closed,<\/li>\n<li>candies[i] is the number of candies in the <span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">\n<p>          i<\/p>\n<p>           t<\/p>\n<p>           h<\/p>\n<p>        i^{th}<\/p>\n<p>     <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.8491em\"><\/span><span class=\"mord\"><span class=\"mord mathnormal\">i<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.8491em\"><span class=\"\" style=\"top: -3.063em;margin-right: 0.05em\"><span class=\"pstrut\" style=\"height: 2.7em\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">t<\/span><span class=\"mord mathnormal mtight\">h<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span> box,<\/li>\n<li>keys[i] is a list of the labels of the boxes you can open after opening the <span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">\n<p>          i<\/p>\n<p>           t<\/p>\n<p>           h<\/p>\n<p>        i^{th}<\/p>\n<p>     <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.8491em\"><\/span><span class=\"mord\"><span class=\"mord mathnormal\">i<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.8491em\"><span class=\"\" style=\"top: -3.063em;margin-right: 0.05em\"><span class=\"pstrut\" style=\"height: 2.7em\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">t<\/span><span class=\"mord mathnormal mtight\">h<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span> box.<\/li>\n<li>containedBoxes[i] is a list of the boxes you found inside the <span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\">\n<p>          i<\/p>\n<p>           t<\/p>\n<p>           h<\/p>\n<p>        i^{th}<\/p>\n<p>     <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.8491em\"><\/span><span class=\"mord\"><span class=\"mord mathnormal\">i<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.8491em\"><span class=\"\" style=\"top: -3.063em;margin-right: 0.05em\"><span class=\"pstrut\" style=\"height: 2.7em\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">t<\/span><span class=\"mord mathnormal mtight\">h<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span> box.<\/li>\n<\/ul>\n<p>You are given an integer array initialBoxes that contains the labels of the boxes you initially have. You can take all the candies in any open box and you can use the keys in it to open new boxes and you also can use the boxes you find in it.<\/p>\n<p>Return the maximum number of candies you can get following the rules above. \u00a0<\/p>\n<h5>Example 1:<\/h5>\n<p>Input: status &#061; [1,0,1,0], candies &#061; [7,5,4,100], keys &#061; [[],[],[1],[]], containedBoxes &#061; [[1,2],[3],[],[]], initialBoxes &#061; [0] Output: 16 Explanation: You will be initially given box 0. You will find 7 candies in it and boxes 1 and 2. Box 1 is closed and you do not have a key for it so you will open box 2. You will find 4 candies and a key to box 1 in box 2. In box 1, you will find 5 candies and box 3 but you will not find a key to box 3 so box 3 will remain closed. Total number of candies collected &#061; 7 &#043; 4 &#043; 5 &#061; 16 candy.<\/p>\n<h5>Example 2:<\/h5>\n<p>Input: status &#061; [1,0,0,0,0,0], candies &#061; [1,1,1,1,1,1], keys &#061; [[1,2,3,4,5],[],[],[],[],[]], containedBoxes &#061; [[1,2,3,4,5],[],[],[],[],[]], initialBoxes &#061; [0] Output: 6 Explanation: You have initially box 0. Opening it you can find boxes 1,2,3,4 and 5 and their keys. The total number of candies will be 6.<\/p>\n<h5>Constraints:<\/h5>\n<ul>\n<li>n &#061;&#061; status.length &#061;&#061; candies.length &#061;&#061; keys.length &#061;&#061; containedBoxes.length<\/li>\n<li>1 &lt;&#061; n &lt;&#061; 1000<\/li>\n<li>status[i] is either 0 or 1.<\/li>\n<li>1 &lt;&#061; candies[i] &lt;&#061; 1000<\/li>\n<li>0 &lt;&#061; keys[i].length &lt;&#061; n<\/li>\n<li>0 &lt;&#061; keys[i][j] &lt; n<\/li>\n<li>All values of keys[i] are unique.<\/li>\n<li>0 &lt;&#061; containedBoxes[i].length &lt;&#061; n<\/li>\n<li>0 &lt;&#061; containedBoxes[i][j] &lt; n<\/li>\n<li>All values of containedBoxes[i] are unique.<\/li>\n<li>Each box is contained in one box at most.<\/li>\n<li>0 &lt;&#061; initialBoxes.length &lt;&#061; n<\/li>\n<li>0 &lt;&#061; initialBoxes[i] &lt; n<\/li>\n<\/ul>\n<p>From: LeetCode Link: 1298. Maximum Candies You Can Get from Boxes<\/p>\n<hr \/>\n<h4>Solution:<\/h4>\n<h6>Ideas:<\/h6>\n<p>Use BFS to process every box that you both possess and can open, while collecting new keys and contained boxes.<\/p>\n<h6>Code:<\/h6>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdlib.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdbool.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">maxCandies<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> status<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> statusSize<span class=\"token punctuation\">,<\/span><br \/>\n               <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> candies<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> candiesSize<span class=\"token punctuation\">,<\/span><br \/>\n               <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span><span class=\"token operator\">*<\/span> keys<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> keysSize<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> keysColSize<span class=\"token punctuation\">,<\/span><br \/>\n               <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span><span class=\"token operator\">*<\/span> containedBoxes<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> containedBoxesSize<span class=\"token punctuation\">,<\/span><br \/>\n               <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> containedBoxesColSize<span class=\"token punctuation\">,<\/span><br \/>\n               <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> initialBoxes<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> initialBoxesSize<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token keyword\">int<\/span> n <span class=\"token operator\">&#061;<\/span> statusSize<span class=\"token punctuation\">;<\/span><br \/>\n    bool<span class=\"token operator\">*<\/span> haveBox <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">calloc<\/span><span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>bool<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    bool<span class=\"token operator\">*<\/span> processed <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">calloc<\/span><span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>bool<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> queue <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">malloc<\/span><span class=\"token punctuation\">(<\/span>n <span class=\"token operator\">*<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">int<\/span> front <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> rear <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> total <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/* Record the boxes initially owned. *\/<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> initialBoxesSize<span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">int<\/span> box <span class=\"token operator\">&#061;<\/span> initialBoxes<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        haveBox<span class=\"token punctuation\">[<\/span>box<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> true<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/* Add initially available open boxes. *\/<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> initialBoxesSize<span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">int<\/span> box <span class=\"token operator\">&#061;<\/span> initialBoxes<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>status<span class=\"token punctuation\">[<\/span>box<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">1<\/span> <span class=\"token operator\">&amp;&amp;<\/span> <span class=\"token operator\">!<\/span>processed<span class=\"token punctuation\">[<\/span>box<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            processed<span class=\"token punctuation\">[<\/span>box<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> true<span class=\"token punctuation\">;<\/span><br \/>\n            queue<span class=\"token punctuation\">[<\/span>rear<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> box<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span>front <span class=\"token operator\">&lt;<\/span> rear<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">int<\/span> box <span class=\"token operator\">&#061;<\/span> queue<span class=\"token punctuation\">[<\/span>front<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        total <span class=\"token operator\">&#043;&#061;<\/span> candies<span class=\"token punctuation\">[<\/span>box<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token comment\">\/* Collect keys. *\/<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> keysColSize<span class=\"token punctuation\">[<\/span>box<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">int<\/span> next <span class=\"token operator\">&#061;<\/span> keys<span class=\"token punctuation\">[<\/span>box<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            status<span class=\"token punctuation\">[<\/span>next<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>haveBox<span class=\"token punctuation\">[<\/span>next<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&amp;&amp;<\/span> <span class=\"token operator\">!<\/span>processed<span class=\"token punctuation\">[<\/span>next<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                processed<span class=\"token punctuation\">[<\/span>next<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> true<span class=\"token punctuation\">;<\/span><br \/>\n                queue<span class=\"token punctuation\">[<\/span>rear<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> next<span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><\/p>\n<p>        <span class=\"token comment\">\/* Collect contained boxes. *\/<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> containedBoxesColSize<span class=\"token punctuation\">[<\/span>box<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">int<\/span> next <span class=\"token operator\">&#061;<\/span> containedBoxes<span class=\"token punctuation\">[<\/span>box<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            haveBox<span class=\"token punctuation\">[<\/span>next<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> true<span class=\"token punctuation\">;<\/span><\/p>\n<p>            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>status<span class=\"token punctuation\">[<\/span>next<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">1<\/span> <span class=\"token operator\">&amp;&amp;<\/span> <span class=\"token operator\">!<\/span>processed<span class=\"token punctuation\">[<\/span>next<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                processed<span class=\"token punctuation\">[<\/span>next<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> true<span class=\"token punctuation\">;<\/span><br \/>\n                queue<span class=\"token punctuation\">[<\/span>rear<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> next<span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token function\">free<\/span><span class=\"token punctuation\">(<\/span>haveBox<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">free<\/span><span class=\"token punctuation\">(<\/span>processed<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">free<\/span><span class=\"token punctuation\">(<\/span>queue<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">return<\/span> total<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1298. Maximum Candies You Can Get from Boxes<br \/>\nYou have n boxes labeled from 0 to n &#8211; 1. You are given four arrays: status, candies, keys, and containedBoxes where:<br \/>\nstatus[i] is 1 if the ith box is open and 0 if the ithi^{th}ith box is clos<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[174,2692,427],"topic":[],"class_list":["post-117805","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-leetcode","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>LeetCode \/\/C - 1298. Maximum Candies You Can Get from Boxes - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/117805.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LeetCode \/\/C - 1298. Maximum Candies You Can Get from Boxes - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"1298. Maximum Candies You Can Get from Boxes You have n boxes labeled from 0 to n - 1. You are given four arrays: status, candies, keys, and containedBoxes where: status[i] is 1 if the ith box is open and 0 if the ithi^{th}ith box is clos\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/117805.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-25T06:08:17+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117805.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/117805.html\",\"name\":\"LeetCode \/\/C - 1298. Maximum Candies You Can Get from Boxes - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-25T06:08:17+00:00\",\"dateModified\":\"2026-10-25T06:08:17+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/117805.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/117805.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117805.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LeetCode \/\/C - 1298. Maximum Candies You Can Get from Boxes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LeetCode \/\/C - 1298. Maximum Candies You Can Get from Boxes - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/117805.html","og_locale":"zh_CN","og_type":"article","og_title":"LeetCode \/\/C - 1298. Maximum Candies You Can Get from Boxes - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"1298. Maximum Candies You Can Get from Boxes You have n boxes labeled from 0 to n - 1. You are given four arrays: status, candies, keys, and containedBoxes where: status[i] is 1 if the ith box is open and 0 if the ithi^{th}ith box is clos","og_url":"https:\/\/www.wsisp.com\/helps\/117805.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-25T06:08:17+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/117805.html","url":"https:\/\/www.wsisp.com\/helps\/117805.html","name":"LeetCode \/\/C - 1298. Maximum Candies You Can Get from Boxes - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-25T06:08:17+00:00","dateModified":"2026-10-25T06:08:17+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/117805.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/117805.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/117805.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"LeetCode \/\/C - 1298. Maximum Candies You Can Get from Boxes"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=117805"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117805\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=117805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=117805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=117805"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=117805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}