Skip to content

Commit 92d7b9f

Browse files
author
zhangzhengxian
committed
7.17
1 parent 82a2477 commit 92d7b9f

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
|43|[Multiply Strings](https://leetcode.com/problems/multiply-strings/)| [JavaScript](./algorithms/Multiply_Strings.js)|Medium|
4040
|46|[Permutations](https://leetcode.com/problems/permutations/)| [JavaScript](./algorithms/Permutations.js)|Medium|
4141
|47|[Permutations II](https://leetcode.com/problems/permutations-ii/)| [JavaScript](./algorithms/PermutationsII.js)|Medium|
42-
|48|[Rotate Image](https://leetcode.com/problems/permutations-ii/)| [JavaScript](./algorithms/RotateImage.js)|Medium|
42+
|48|[Rotate Image](https://leetcode.com/problems/rotate-image/)| [JavaScript](./algorithms/RotateImage.js)|Medium|
43+
|49|[Group Anagrams](https://leetcode.com/problems/group-anagrams/)| [JavaScript](./algorithms/group Anagrams.js)|Medium|
44+
|50|[Pow(x, n)](https://leetcode.com/problems/powx-n/)| [JavaScript](./algorithms/Pow(x, n).js)|Medium|
4345
|69|[Sqrt(x)](https://leetcode.com/problems/sqrtx/)| [JavaScript](./algorithms/Sqrt(x).js)|Easy|
4446
|371|[Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/)| [JavaScript](./algorithms/Sum_of_Two_Integers.js)|Easy|
4547
|372|[Super Pow](https://leetcode.com/problems/super-pow/)| [JavaScript](./algorithms/SuperPow.js)|Medium|

algorithms/Pow(x, n).js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number} x
3+
* @param {number} n
4+
* @return {number}
5+
*/
6+
var myPow = function(x, n) {
7+
var flag = false,
8+
p = x,
9+
res = 1
10+
if (n < 0) {
11+
flag = true;
12+
}
13+
for (var i = Math.abs(n); i > 0 ; i = Math.floor(i/2)) {
14+
if (i % 2 !== 0) {
15+
res = res * p;
16+
}
17+
p = p * p;
18+
}
19+
result = flag ? 1 / res : res;
20+
return result
21+
};

algorithms/groupAnagrams.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {string[]} strs
3+
* @return {string[][]}
4+
*/
5+
var groupAnagrams = function(strs) {
6+
var result = [],
7+
obj = {},
8+
pipe = function(str) {
9+
return str.split('').sort().join('');
10+
}
11+
for (var i = 0; i < strs.length; i++ ) {
12+
if (obj[pipe(strs[i])] === undefined) {
13+
obj[pipe(strs[i])] = result.length;
14+
result.push([].concat(strs[i]));
15+
} else {
16+
result[obj[pipe(strs[i])]].push(strs[i]);
17+
}
18+
}
19+
return result;
20+
};

0 commit comments

Comments
 (0)