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)