-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a43283b
commit 168ac39
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @param {number[]} temperatures | ||
* @return {number[]} | ||
*/ | ||
var dailyTemperatures = function(temperatures) { | ||
const stack = []; | ||
const result = new Array(temperatures.length).fill(0); | ||
|
||
for(let i =0;i<temperatures.length ;i++){ | ||
while(stack.length >0 && temperatures[i] > temperatures[stack[stack.length -1]]){ | ||
const idx = stack.pop(); | ||
result[idx] = i - idx | ||
} | ||
stack.push(i); | ||
} | ||
return result | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @param {string} num1 | ||
* @param {string} num2 | ||
* @return {string} | ||
*/ | ||
var multiply = function(num1, num2) { | ||
const m = num1.length | ||
const n = num2.length | ||
const product = Array(m+n).fill(0) | ||
|
||
for(let i =m-1;i>=0;i--){ | ||
for(let j =n-1;j>=0;j--){ | ||
const mul = (num1[i] - '0') * (num2[j] - '0') | ||
const sum = mul + product[i+j+1] | ||
product[i+j] += Math.floor(sum/10) | ||
product[i+j+1] = sum % 10 | ||
} | ||
} | ||
|
||
let result = '' | ||
for(let digit of product){ | ||
if(!(result.length === 0 && digit === 0)){ | ||
result += digit | ||
} | ||
} | ||
return result.length === 0 ? '0' : result | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @param {number} x | ||
* @param {number} n | ||
* @return {number} | ||
*/ | ||
var myPow = function(x, n) { | ||
if(n === 0) return 1 | ||
if(n<0) return 1/myPow(x,-n) | ||
|
||
let result = 1 | ||
|
||
while(n>0){ | ||
if(n% 2=== 1){ | ||
result *=x | ||
} | ||
x *= x | ||
n = Math.floor(n/2) | ||
} | ||
return result | ||
}; |