1 /// <summary>2 ///Solution A3 ///Pass rate 100%4 /// </summary>5 /// <param name= "A" ></param>6 /// <returns></returns>7 Public Static intSolution (int[] A)8 {9 intSumL = a[0];Ten intSUMR =0; One intMin =0; A for(inti =1; i < a.length; i++) -SUMR + =A[i]; -min = Math.Abs (SumL-SUMR); the for(inti =1; I < a.length-1; i++) - { -SumL + =A[i]; -SUMR-=A[i]; + if(Math.Abs (SUML-SUMR) <min) -min = Math.Abs (SumL-SUMR); + } A returnmin; at } - - /// <summary> - ///Solution B - ///Pass rate 66% - ///It's unclear where the problem is and you can't see the failed test cases in /// </summary> - /// <param name= "A" ></param> to /// <returns></returns> + Public Static intSolution (int[] A) - { the inti =0; * intj = a.length-1; $ intsum =0;Panax Notoginseng while(I <j) - { the if(Math.Abs (sum + a[i]) < Math.Abs (Sum-A[j])) + { ASum + =A[i]; thei++; + } - Else if(Math.Abs (sum + a[i]) > Math.Abs (Sum-A[j])) $ { $Sum-=A[j]; -j--; - } the Else - {WuyiSum + =A[i]; theSum-=A[j]; -i++; Wuj--; - } About } $ if(i = =j) -sum = math.abs (sum + a[i]) < Math.Abs (Sum-a[i])? Math.Abs (sum + a[i]): Math.Abs (Sum-a[i]); - returnmath.abs (sum); -}
Tape equilibrium "Legacy issues"