Skip to content

Commit

Permalink
20160712
Browse files Browse the repository at this point in the history
更新一题
  • Loading branch information
SmokerX committed Jul 12, 2016
1 parent 510d0c5 commit b20d820
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
28 changes: 28 additions & 0 deletions Algorithms/372. Super Pow/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Solution {
public int superPow(int a, int[] b) {
a%=1337;
if(isZero(b)){
return 1;
}
int other=b[b.length-1]%2==0?1:a;
half(b);
int one=superPow(a,b);
return one*one%1337*other%1337;
}
public void half(int[] b){
int tmp=0;
for(int i=0;i<b.length;i++){
b[i]+=tmp*10;
tmp=b[i]%2;
b[i]=b[i]/2;
}
}
public boolean isZero(int[] b){
for(int i=0;i<b.length;i++){
if(b[i]!=0){
return false;
}
}
return true;
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,5 @@
|369|[Plus One Linked List](https://leetcode.com/problems/plus-one-linked-list/)|Medium|noBuy|noBuy|noBuy|noBuy|noBuy|
|370|[Range Addition](https://leetcode.com/problems/range-addition/)|Medium|noBuy|noBuy|noBuy|noBuy|noBuy|
|371|[Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/)|Easy|noNote|[Java](https://github.com/corpsepiges/leetcode/blob/master/Algorithms/371. Sum of Two Integers/Solution.java)|no|no|no|
|372|[Super Pow](https://leetcode.com/problems/super-pow/)|Medium|noNote|no|no|no|no|
|372|[Super Pow](https://leetcode.com/problems/super-pow/)|Medium|noNote|[Java](https://github.com/corpsepiges/leetcode/blob/master/Algorithms/372. Super Pow/Solution.java)|no|no|no|
|373|[Find K Pairs with Smallest Sums](https://leetcode.com/problems/find-k-pairs-with-smallest-sums/)|Medium|noNote|[Java](https://github.com/corpsepiges/leetcode/blob/master/Algorithms/373. Find K Pairs with Smallest Sums/Solution.java)|no|no|no|
28 changes: 28 additions & 0 deletions java/372. Super Pow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Solution {
public int superPow(int a, int[] b) {
a%=1337;
if(isZero(b)){
return 1;
}
int other=b[b.length-1]%2==0?1:a;
half(b);
int one=superPow(a,b);
return one*one%1337*other%1337;
}
public void half(int[] b){
int tmp=0;
for(int i=0;i<b.length;i++){
b[i]+=tmp*10;
tmp=b[i]%2;
b[i]=b[i]/2;
}
}
public boolean isZero(int[] b){
for(int i=0;i<b.length;i++){
if(b[i]!=0){
return false;
}
}
return true;
}
}

0 comments on commit b20d820

Please sign in to comment.