diff options
author | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
commit | a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 (patch) | |
tree | e2a2b3f49f9fb741be81415266ac93e74cff42ec /other/max_sum_circular_subarr.cpp | |
parent | 694ad5ed71edcb1deccab54b72d706b779918276 (diff) | |
download | leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.tar.gz leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.zip |
chore: remove old cpp and rust solutions
Diffstat (limited to 'other/max_sum_circular_subarr.cpp')
-rw-r--r-- | other/max_sum_circular_subarr.cpp | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/other/max_sum_circular_subarr.cpp b/other/max_sum_circular_subarr.cpp deleted file mode 100644 index a86eafa..0000000 --- a/other/max_sum_circular_subarr.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// 918. Maximum Sum Circular Subarray -#include "leetcode.h" - -/* - * given: circular int array 'nums' of length 'n', return the max possible - * sum of non-empty subarray of 'nums' - * - * a circular array means the end of the array connects to the beginning. - * formally, the previous element of 'nums[i]' is 'nums[(i -/+ 1) % n]' - * - * a subarray may only include each element of the fixed buffer 'nums' at - * most once. formally, for a subarray 'nums[i], nums[i + 1], ..., nums[j]' - * there does not exist i <= k1, k2 <= j with k1 % n == k2 % n - */ - -class Solution { -public: - int maxSubarraySumCircular(vector<int> &nums) { - int sum = 0; - for (int i : nums) - sum += i; - int s1 = helper(nums.begin(), nums.end()); - for (int &i : nums) - i *= -1; - int s2 = sum + helper(nums.begin(), nums.end() - 1); - int s3 = sum + helper(nums.begin() + 1, nums.end()); - return max(s1, max(s2, s3)); - } - -private: - int helper(vector<int>::iterator p, vector<int>::iterator q) { - int res = INT_MIN, n = 0; - for (auto i = p; i != q; i++) { - n += *i; - res = max(res, n); - if (n < 0) - n = 0; - } - return res; - } -}; - -int main() { - Solution obj; - vector<int> nums1 = {-2}, nums2 = {5, -3, 5}, nums3 = {-3, -2, -3}; - cout << obj.maxSubarraySumCircular(nums1) << endl; // expect: 3 - cout << obj.maxSubarraySumCircular(nums2) << endl; // expect: 10 - cout << obj.maxSubarraySumCircular(nums3) << endl; // expect: -2 -} |