File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 50
50
1313|[ Decompress Run-Length Encoded List] ( ./1313-decompress-run-length-encoded-list.js ) |Easy|
51
51
1317|[ Convert Integer to the Sum of Two No-Zero Integers] ( ./1317-convert-integer-to-the-sum-of-two-no-zero-integers.js ) |Easy|
52
52
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|
53
54
54
55
## License
55
56
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments