Skip to content

Commit c92e811

Browse files
authored
[LeetCode - Easy] Convert Date to Binary (#53)
1 parent 5bfd552 commit c92e811

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {string} date
3+
* @return {string}
4+
*/
5+
6+
function convertBinary(num){
7+
const stack = [];
8+
while(num > 0){
9+
stack.push(num%2);
10+
num = Math.floor(num/2);
11+
}
12+
return stack.reverse().join("");
13+
}
14+
var convertDateToBinary = function(date) {
15+
const [year, month, day] = date.split("-");
16+
const y = convertBinary(Number(year))
17+
const m = convertBinary(Number(month))
18+
const d = convertBinary(Number(day));
19+
return `${y}-${m}-${d}`
20+
};

0 commit comments

Comments
 (0)