Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 70686f1

Browse files
committed
68th problem
1 parent 6da4bdd commit 70686f1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

‎61-70/67. Add Binary.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var addBinary = function(a, b) {
2+
let sum = BigInt(`0b${a}`) + BigInt(`0b${b}`);
3+
return sum.toString(2);
4+
};

‎61-70/68. Text Justification.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var fullJustify = function(words, maxWidth) {
2+
let [line,spaces,addSpace,minSpaces] = [0,0,0,""]
3+
for (let res = [[]], i = 0, letters = 0; i <= words.length; letters += words[i++].length) {
4+
let row = res[res.length - 1];
5+
let len = row.length
6+
if (i == words.length || len && letters + len + words[i].length > maxWidth) {
7+
if (len == 1 || i == words.length) {
8+
res[res.length - 1] = row.join(' ') + ' '.repeat(maxWidth - letters - len + 1);
9+
if (i === words.length) return res;
10+
} else {
11+
line = row[0];
12+
spaces = maxWidth - letters;
13+
minSpaces = ' '.repeat(Math.floor(spaces / (len- 1)));
14+
addSpace = spaces % (len - 1);
15+
for (let w = 1; w < len; w++) {
16+
line += minSpaces + (w <= addSpace ? ' ' : '') + row[w];
17+
}
18+
res[res.length - 1] = line;
19+
}
20+
res.push([]);
21+
letters = 0;
22+
}
23+
res[res.length - 1].push(words[i]);
24+
}
25+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /