Get the App
SLTechnology News&Howtos  ›  Development  › 

How to find the maximum sum of continuous subarrays in C language

Shulou Source: shulou.com Published: 2022-06-02 02:18:18 10月26日 Update

This article mainly introduces how to find the maximum sum of continuous subarrays in c language, which has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article.

HZ occasionally uses professional questions to fool students who are not computer majors. After the test group meeting today, he spoke again: in the ancient one-dimensional pattern recognition, it is often necessary to calculate the maximum sum of continuous subvectors, and when the vectors are all positive, the problem can be easily solved. But if the vector contains a negative number, should it include a negative number and expect the positive number next to it to make up for it? For example: {6furome 3meme 2jin7 fuzz 151je 2jin2}, the maximum sum of continuous subvectors is 8 (starting from 0th to 3rd). Will you be fooled by him?

Class Solution {public: int FindGreatestSumOfSubArray (vector array) {if (array.size () = = 0) {return 0;} int greatest_sum = array [0]; for (int I = 0; I

< array.size(); ++i) { int subArraySum = array[i]; if (subArraySum >

Greatest_sum) {greatest_sum = subArraySum;} for (int j = iTunes 1; j

< array.size(); ++j) { subArraySum += array[j]; if (subArraySum >

Greatest_sum) greatest_sum = subArraySum;}} return greatest_sum;}} Thank you for reading this article carefully. I hope the article "how to find the maximum sum of continuous subarrays in c language" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Maximum vector article array language major positive number negative number question antiquity value interest classmate at the same time time more friends pattern knowledge editing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn macOS NVidia MySQL Xiaomi