{"id":10322,"date":"2025-04-10T21:04:13","date_gmt":"2025-04-11T04:04:13","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=10322"},"modified":"2025-04-10T21:04:40","modified_gmt":"2025-04-11T04:04:40","slug":"leetcode-2011-final-value-of-variable-after-performing-operations","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/simulation\/leetcode-2011-final-value-of-variable-after-performing-operations\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 2011. Final Value of Variable After Performing Operations"},"content":{"rendered":"\n<p>C++ \u4e5f\u80fd\u5199one-liner\u4e86\u3002<\/p>\n\n\n\n<p>\u65f6\u95f4\u590d\u6742\u5ea6\uff1aO(n)<br>\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(1)<\/p>\n\n\n\n<pre lang=\"c++\">\nclass Solution {\npublic:\n  int finalValueAfterOperations(vector<string>& operations) {\n    return accumulate(begin(operations), end(operations), 0, [](const auto s, const auto& op){\n      return s + (op[1] == '+' ? 1 : -1);\n    });\n  }\n};\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>C++ \u4e5f\u80fd\u5199one-liner\u4e86\u3002 \u65f6\u95f4\u590d\u6742\u5ea6\uff1aO(n)\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(1) class Solution { public: int finalValueAfterOperations(vector&#038; operations) { return accumulate(begin(operations), end(operations), 0, [](const auto s, const auto&#038; op){ return s + (op[1]&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[222,179,4],"class_list":["post-10322","post","type-post","status-publish","format-standard","hentry","category-simulation","tag-easy","tag-simulation","tag-string","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/10322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=10322"}],"version-history":[{"count":3,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/10322\/revisions"}],"predecessor-version":[{"id":10325,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/10322\/revisions\/10325"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=10322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=10322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=10322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}