Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report