Skip to content

Commit 5355058

Browse files
committed
53th problem
1 parent 317a4ea commit 5355058

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

50. Pow(x, n).js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var myPow = function(x, n) {
2+
if(x == 1){return 1}
3+
if(n == 0){return 1}
4+
if(x == -1){
5+
if(n%2 == 0){return 1}
6+
else{return -1}
7+
}
8+
let k = x
9+
if(n > 1){
10+
while( n > 1){
11+
x *= k
12+
n--
13+
}
14+
return x
15+
}else{
16+
while( n < 1){
17+
x *= 1/k
18+
n++
19+
}
20+
return x
21+
}
22+
};

53. Maximum Subarray.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var maxSubArray = function(nums) {
2+
let ans = -9999999
3+
let sum = 0
4+
for(let i = 0 ; i < nums.length; i ++){
5+
sum+=nums[i]
6+
ans=Math.max(sum,ans)
7+
sum=Math.max(sum,0)
8+
}
9+
return ans
10+
};

0 commit comments

Comments
 (0)