{"id":8145,"date":"2024-04-13T09:27:11","date_gmt":"2024-04-13T01:27:11","guid":{"rendered":"https:\/\/white-night.club\/?p=8145"},"modified":"2024-04-13T09:27:26","modified_gmt":"2024-04-13T01:27:26","slug":"ad183","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2024\/04\/13\/ad183\/","title":{"rendered":"1413. \u9010\u6b65\u6c42\u548c\u5f97\u5230\u6b63\u6570\u7684\u6700\u5c0f\u503c"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode.cn\/problems\/minimum-value-to-get-positive-step-by-step-sum\/description\/\">https:\/\/leetcode.cn\/problems\/minimum-value-to-get-positive-step-by-step-sum\/description\/<\/a><\/p>\n\n\n\n<p>\u6b38\uff0c\u524d\u7f00\u548c\u3002<\/p>\n\n\n\n<p>\u9898\u76ee\u7684\u610f\u601d\u5c31\u662f\uff1a\u9010\u9879\u76f8\u52a0\uff0c\u8981\u6c42\u5b58\u5728\u67d0\u4e2ax\uff0c\u4f7f\u5f97x+item\u59cb\u7ec8\u5927\u4e8e0\u3002<\/p>\n\n\n\n<p>\u90a3\u5c31\u662f\u5148\u6c42\u524d\u7f00\u548c\u5457\uff0c\u63a5\u7740\u627e\u51fa\u524d\u7f00\u548c\u91cc\u9762\u6700\u5c0f\u7684\u90a3\u4e00\u9879\u3002\u7531\u4e8e\u8981\u6c42\u7684\u662fx+item\u5927\u4e8e0\uff0c\u6240\u4ee5\u8981\u5148\u53d6\u7edd\u5bf9\u503c\u518d\u52a01\u3002<\/p>\n\n\n\n<p>\u4e0d\u8fc7golang\u7684return\u4e0d\u80fd\u7528\u4e09\u5143\u8868\u8fbe\u5f0f\uff0c\u53ea\u80fd\u5199\u4e2aif-else\uff0c\u8fd8\u662f\u633a\u9ebb\u70e6\u7684\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Go<\/span><span role=\"button\" tabindex=\"0\" data-code=\"func minStartValue(nums []int) int {\n    length:=len(nums)\n    sum:=make([]int,length+1)\n    min:=1\n    for i:=0;i&lt;length;i++{\n        sum[i+1]=sum[i]+nums[i]\n        if min&gt;sum[i+1]{\n            min=sum[i+1]\n        }\n    }\n    if min&gt;0{\n        return 1\n    }else{\n        return -min+1\n    }\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">func<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">minStartValue<\/span><span style=\"color: #D4D4D4\">(nums []<\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">length<\/span><span style=\"color: #D4D4D4\">:=<\/span><span style=\"color: #DCDCAA\">len<\/span><span style=\"color: #D4D4D4\">(nums)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">sum<\/span><span style=\"color: #D4D4D4\">:=<\/span><span style=\"color: #DCDCAA\">make<\/span><span style=\"color: #D4D4D4\">([]<\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">,length+<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">min<\/span><span style=\"color: #D4D4D4\">:=<\/span><span style=\"color: #B5CEA8\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\">:=<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;i&lt;length;i++{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        sum[i+<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">]=sum[i]+nums[i]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> min&gt;sum[i+<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">]{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #9CDCFE\">min<\/span><span style=\"color: #D4D4D4\">=sum[i+<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> min&gt;<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #B5CEA8\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> -min+<\/span><span style=\"color: #B5CEA8\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u7f00\u548c<\/p>\n","protected":false},"author":1,"featured_media":7932,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/8145"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=8145"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/8145\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/7932"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=8145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=8145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=8145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}