๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/Leetcode

[Leetcode,c++] Maximum Subarray

by dkswnkk 2021. 11. 9.

๋ฌธ์ œ

 

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

 

์ฝ”๋“œ

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

๋Œ“๊ธ€