Skip to content

Commit 6ede739

Browse files
committed
Add solution #1324
1 parent eb35369 commit 6ede739

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
1313|[Decompress Run-Length Encoded List](./1313-decompress-run-length-encoded-list.js)|Easy|
5151
1317|[Convert Integer to the Sum of Two No-Zero Integers](./1317-convert-integer-to-the-sum-of-two-no-zero-integers.js)|Easy|
5252
1318|[Minimum Flips to Make a OR b Equal to c](./1318-minimum-flips-to-make-a-or-b-equal-to-c.js)|Medium|
53+
1324|[Print Words Vertically](./1324-print-words-vertically.js)|Medium|
5354

5455
## License
5556

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* 1324. Print Words Vertically
3+
* https://leetcode.com/problems/print-words-vertically/
4+
* Difficulty: Medium
5+
*
6+
* Given a string s. Return all the words vertically in the same
7+
* order in which they appear in s.
8+
* Words are returned as a list of strings, complete with spaces
9+
* when is necessary. (Trailing spaces are not allowed).
10+
* Each word would be put on only one column and that in one
11+
* column there will be only one word.
12+
*/
13+
14+
/**
15+
* @param {string} s
16+
* @return {string[]}
17+
*/
18+
var printVertically = function(s) {
19+
const result = [];
20+
s.split(/\s+/).forEach((word, i) => word.split('').forEach((letter, j) => {
21+
result[j] = result[j] || '';
22+
result[j] += letter.padStart(i - result[j].length + 1, ' ');
23+
}));
24+
return result;
25+
};

0 commit comments

Comments
 (0)