Tape equilibrium "Legacy issues"

Source: Internet
Author: User

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"

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.