Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 14484f7

Browse files
committed
Add solution #372
1 parent babbec9 commit 14484f7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

0372-super-pow.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* 372. Super Pow
3+
* https://leetcode.com/problems/super-pow/
4+
* Difficulty: Medium
5+
*
6+
* Your task is to calculate ab mod 1337 where a is a positive integer and b
7+
* is an extremely large positive integer given in the form of an array.
8+
*/
9+
10+
/**
11+
* @param {number} a
12+
* @param {number[]} b
13+
* @return {number}
14+
*/
15+
var superPow = function(a, b) {
16+
return helper(BigInt(a), BigInt(b.join('')), 1337n);
17+
};
18+
19+
function helper(a, b, mod) {
20+
let r = 1n;
21+
22+
while (b > 0n) {
23+
if (b % 2n == 1) {
24+
r = r * a % mod;
25+
}
26+
b >>= 1n;
27+
a = a * a % mod;
28+
}
29+
30+
return Number(r);
31+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
350|[Intersection of Two Arrays II](./0350-intersection-of-two-arrays-ii.js)|Easy|
156156
367|[Valid Perfect Square](./0367-valid-perfect-square.js)|Easy|
157157
371|[Sum of Two Integers](./0371-sum-of-two-integers.js)|Medium|
158+
372|[Super Pow](./0372-super-pow.js)|Medium|
158159
374|[Guess Number Higher or Lower](./0374-guess-number-higher-or-lower.js)|Medium|
159160
383|[Ransom Note](./0383-ransom-note.js)|Easy|
160161
387|[First Unique Character in a String](./0387-first-unique-character-in-a-string.js)|Easy|

0 commit comments

Comments
 (0)