| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- generic
- docker
- type
- BOJ
- var
- vue.js
- VUE
- webpack
- Python
- loop
- C++
- machine learning
- JavaScript
- scss
- security
- leetcode
- npm
- Clone
- property
- dotenv
- C#
- git
- nginx
- vuetify
- AI
- 보안
- bash
- TypeScript
- 앙상블
- condition
Archives
- Today
- Total
ice rabbit programming
[LeetCode] Maximum Subarray 본문
728x90
https://leetcode.com/problems/maximum-subarray/
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
주어진 배열의 부분집합 중 가장 합이 큰 경우이다.
사실 이 때까지 푼 easy 단계 중 가장 생각이 오래 걸렸던 것 같다.
연속된 합이 가장 큰 경우의 결과값을 return하였다.
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int ans=nums[0],sum=0;
for(int i=0;i<nums.size();i++){
sum+=nums[i];
ans=max(sum,ans);
sum=max(sum,0);
}
return ans;
}
};728x90
'PS > LeetCode' 카테고리의 다른 글
| [LeetCode] Remove Duplicates From Sorted List (0) | 2020.04.15 |
|---|---|
| [LeetCode] Climbing Stairs (0) | 2020.04.15 |
| [LeetCode] Valid Parenthese (0) | 2020.04.15 |
| [LeetCode] Longest Common Prefix (0) | 2020.04.15 |
| [LeetCode] Remove Element (0) | 2020.04.15 |