lintcode.44 Minimum Sub-array

Source: Internet
Author: User
Tags lintcode

The least-boy array

    • Describe
    • Notes
    • Data
    • Evaluation

Given an array of integers, find a sub-array with the minimum and. Returns its minimum and.

Precautions

A sub-array contains at least one number

Have you ever encountered this problem in a real interview? YesWhich company is asking you this question?AirbnbAmazonlinkedin cryptic Studios Span class= "BTN Btn-xs btn-white Company" >dropbox apple epic Systems tinyco yelp hedvig zenefits uber snapchat yahoo microsoft bloomberg Thank you for your feedback Sample Example

Given array [1,-1,-2, 1], return-3

labelLintcode Copyright Greedy subarray Array violence
Class Solution {public:    /     * * @param nums:a List of integers     * @return: A integer indicate the sum of minimum Subarray     *    /int Minsubarray (vector<int> &nums) {        //write your code here        int S=nums.size ( );        int res=nums[0];        for (int i=0;i<s;i++)        {            int cn=nums[i];            if (cn<res)                RES=CN;            for (int j=i+1;j<s;j++)            {                cn+=nums[j];                if (cn<=res)                    res=cn;            }        }        return res;    }};

Greedy

Class Solution {public:    /     * * @param nums:a List of integers     * @return: A integer indicate the sum of minimum Subarray     *    /int Minsubarray (vector<int> &nums) {        //write your code here        int S=nums.size (); C7/>int Res=nums[0];        int cn=0;        for (int i=0;i<s;i++)        {            cn +=nums[i];            if (RES>CN)                RES=CN;            if (cn>0)                cn=0;        }        return res;    }};

  

lintcode.44 Minimum Sub-array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.