diff --git a/.github/workflows/cppstylecheck.yml b/.github/workflows/cppstylecheck.yml deleted file mode 100644 index bf49c26..0000000 --- a/.github/workflows/cppstylecheck.yml +++ /dev/null @@ -1,3 +0,0 @@ - - name: C++ Style Check - uses: coleaeason/actions-uncrustify@v1 - diff --git a/cpp/198-House-Robber.cpp b/cpp/198-House-Robber.cpp new file mode 100644 index 0000000..33ab49d --- /dev/null +++ b/cpp/198-House-Robber.cpp @@ -0,0 +1,17 @@ +class Solution { +public: + int rob(vector& nums) { + int rob(vector& nums) { +if (nums.empty()) return 0; +int n = nums.size(); +if (n == 1) return nums[0]; +int pre2 = 0, pre1 = 0, cur; +for (int i = 0; i < n; ++i) { +cur = max(pre2 + nums[i], pre1); +pre2 = pre1; +pre1 = cur; +} +return cur; +} + } +}; \ No newline at end of file