public static int two SumReallyFastUnique (int[] a) { Arrays. sort (a); int lo = 0; int hi = a.length-1; int count = 0;

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

public static int two SumReallyFastUnique (int[] a) { Arrays. sort (a); int lo = 0; int hi = a.length-1; int count = 0;

Post by answerhappygod »

Public Static Int Two Sumreallyfastunique Int A Arrays Sort A Int Lo 0 Int Hi A Length 1 Int Count 0 1
Public Static Int Two Sumreallyfastunique Int A Arrays Sort A Int Lo 0 Int Hi A Length 1 Int Count 0 1 (52.45 KiB) Viewed 51 times
public static int two SumReallyFastUnique (int[] a) { Arrays. sort (a); int lo = 0; int hi = a.length-1; int count = 0; while (lo <hi) { int sum = a[10] + a[hi]; if (sum < 0) lo++; else if (sum > 0) --hi; else { count++; lo++; --hi; } } return count; } 1 o lg N N O N lg N O N2 O N2 lg N

public static double accumulateSorted (double[] a) { Arrays. sort (a); double sum = 0.0; for (int i = a.length-1; i >= 0; i--) += a; return sum; } sum 1 lg N O N () N lg N () N2 N2 lg N

public static int multiply (int a, int b) { int result = 0; while (b != 0) { if (b% 2 != 0) result += a; result += result; b = 2; } return result; 1 lg N N N lg N N2 N2 lg N

public static int power (int a, int b) { int result = 1; while (b != 0) { if (b % 2 != 0) result *= a; result *= result; b/= 2; } return result; } 1 lg N N O N lg N O N2 O N2 lg N
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply