Software Engineering Personal Jobs 04-integer array of maximum Subarray and (second edition)

Source: Internet
Author: User

Requirements:
Enter a one-dimensional shape array with positive and negative numbers in the array.
One-dimensional arrays end-to-end, like one end-to-end tape.
One or more consecutive integers in an array make up a sub-array, each of which has a and. The maximum value for the and of all sub-arrays.

Design ideas:

1 set the number of the parameter leader is n, create an auxiliary array of length 2n, in order to assign two times the value

2 each sub-array starting with I has n, i.e. from I to N+i (i<=n)

3 sums the resulting subarray together to determine the maximum value in the array.

Source:

Import Java.util.Vector;

public class Maxlistnumber {
public static int maxlist (int []num) {
int max=-99;
int len=num.length;
if (len<=0) {
System.out.println ("The array is empty. ");
}
else {
Vector<integer> numx=new vector<> ();
Int[]number=new Int[2*len];
for (int i=0;i<len;i++) {

Number[i]=num[i];
SYSTEM.OUT.PRINTLN ("array element:" +num[i]);
Number[len+i]=num[i];
}
for (int i=0;i<len;i++) {
int temp;
int sum=0;
int count=0;
for (int k=i;k<number.length;k++) {
if (Count>=len)
Break
TEMP=NUMBER[K];
Sum=sum+temp;
Numx.add (sum);
count++;
}
}
Max=numx.get (0);
for (int i=0;i<numx.size (); i++) {
if (Max<numx.get (i)) {
Max=numx.get (i);
}
}
}
return Max;
}
public static int maxlist (int [][]num) {
int max=num[0][0];
for (int i=0;i<5;i++) {

}
return 0;

}
public static void Main (String args[]) {

int []number=new int[6];
for (int i=0;i<6;i++) {
number[i]= (int) (Math.random () *10-5);
}
int max=maxlist (number);
System.out.println ("The number of the largest sub-array and:" +max);
}
}

Results

  

Summarize:

Increase time efficiency by consuming space (reducing time complexity)

Software Engineering Personal Jobs 04-integer array of maximum Subarray and (second edition)

Related Article

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.