Maximum Subarray - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
int maxSubArray(vector<int>& nums){
int currentSum = 0;
int bestSum = INT_MIN;
for(auto& ele : nums){
currentSum = std::max(ele, currentSum + ele);
if(currentSum > bestSum){
bestSum = currentSum;
}
}
return bestSum;
}
'Problem set' 카테고리의 다른 글
[LeetCode] Sort Colors (0) | 2022.08.30 |
---|---|
[LeetCode] Sort-Array-By-Parity-ii (0) | 2022.08.26 |
[LeetCode] Find Pivot Index (0) | 2022.08.26 |
[LeetCode] Move Zeroes (0) | 2022.08.26 |
[백준] 1967 트리의 지름 (0) | 2021.02.20 |