๋ฌธ์
์ฝ๋
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int dp[100001]={0, };
int ans=-1e9;
if(nums.size()==1) return nums.back();
for(int i=0; i<nums.size(); i++){
dp[i+1]=max(nums[i]+dp[i],nums[i]);
ans= max(ans,dp[i+1]);
}
return ans;
}
};
ํ์ด
๊ฐ๋จํ dp ๋ฌธ์ ์์ต๋๋ค.
'Algorithm ๐ง๐ปโ๐ป > Leetcode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Leetcode,c++] Permutations (0) | 2021.11.10 |
---|---|
[Leetcode,c++] Best Time to Buy and Sell Stock (0) | 2021.11.10 |
[Leetcode,c++] Climbing Stairs (0) | 2021.11.09 |
[Leetcode,c++] Valid Parentheses (0) | 2021.11.09 |
[Leetcode,c++] Palindrome Number (0) | 2021.11.09 |
[Leetcode,c++] Search Insert Position (0) | 2021.11.09 |
๋๊ธ