MCPcopy Index your code
hub / github.com/careercup/ctci / total

Method total

java/Chapter 9/Question9_11/Question.java:258–274  ·  view source on GitHub ↗
(int n)

Source from the content-addressed store, hash-verified

256 }
257
258 public static int total(int n) {
259 // Function to return (2n) ! / ((n+1)! * n!)
260
261 // To keep the numbers small, we divide by i when possible to do evenly. If not,
262 // we store up the remainder and divide when possible.
263 long num = 1;
264 long rem = 1;
265 for (int i = 2; i <= n; i++) {
266 num *= (n + i);
267 rem *= i;
268 if (num % rem == 0) {
269 num /= rem;
270 rem = 1;
271 }
272 }
273 return (int)num;
274 }
275
276 public static int countDPEff(String exp, boolean result, int start, int end, HashMap<String, Integer> cache) {
277 String key = "" + start + end;

Callers 1

countDPEffMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected