deno.land / x / masx200_leetcode_test@10.6.5 / recursive-mulitply-lcci / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
export default function multiply(x: number, y: number): number { if (!Number.isInteger(y) || !Number.isInteger(x)) { throw Error("not integer"); } if ( Number.isNaN(x) || Number.isNaN(y) || !Number.isFinite(x) || !Number.isFinite(y) ) { throw Error("Invalid number"); } return x < 0 ? -multiply(-x, y) : y < 0 ? -multiply(x, -y) : x === 0 ? 0 : y === 0 ? 0 : x === 1 ? y : y === 1 ? x : x < y ? multiply(y, x) : y & 1 ? x + multiply(x, y - 1) : multiply(x + x, Math.abs(y >> 1));}
masx200_leetcode_test

Version Info

Tagged at
a year ago