There is an array [0.5, 3]. You can find out the number of frequencies that match the maximum number of frequencies/array length>, if yes, place the subscript Of this number. If no-1 is returned
VaR A = [5, 3, 4, 6, 3, 3]
For (VAR I = 0, CI, r = {}; CI = A [I]; I ++ ){
If (R [CI]) {
R [CI]. idx. Push (I );
R [CI]. Count ++;
} Else {
R [CI] = {idx: [I], Count: 1}
}
}
VaR F =-1, L = A. length;
For (VAR p in r ){
If (R [p]. Count/L> 0.5) F = R [p]. idx;
}
Alert (f );
There is an array [5, 0,-5,-4, 5], and a positive or negative number is calculated. The frequency of each number is calculated.
VaR A = [5, 3, 4, 6,-3,-3]
For (VAR I = 0, CI, r = {}; CI = A [I ++];) {
If (R [math. Abs (CI)]) {
R [math. Abs (CI)] ++
} Else {
R [math. Abs (CI)] = 1;
}
}
VaR S = [];
For (VAR p in r ){
S. Push (R [p]);
}
Alert (s );
Subsequences with sequences [5, 0, 2,-6, 4] can have [5, 0], [5, 0, 2] [2,-6], [5, 0, 2, -6, 4], but not [5, 2], [5,-6]
Returns the sum of the largest sequences. In this example, the largest sequence is [5, 0, 2] = 7.
VaR A = [-6, 0, 2, 5, 4], max = 0;
For (VAR I = 0, L = A. length; I <L-1; I ++ ){
For (var j = I; j <L; j ++ ){
For (var tmp = 0, K = I; k <= J; k ++ ){
TMP = TMP + A [k];
}
If (TMP> MAX) max = TMP;
}
}
Alert (max );
Winter reply
Question 1 <textarea id="runcode21773"></textarea>
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]
If you do not consider the convenient JavaScript Object, then ......
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]
Third bug with full negative number
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]