We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 388dbb5 commit ce25b57Copy full SHA for ce25b57
1324-print-words-vertically.js
@@ -0,0 +1,30 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {string[]}
4
+ */
5
+const printVertically = function(s) {
6
+ const arr = s.split(' ').filter(e => e !== '')
7
+ const m = arr.length
8
+ let n = 0
9
+ for(const e of arr) {
10
+ n = Math.max(n, e.length)
11
+ }
12
+
13
+ const mat = Array.from({ length: m }, () => Array(n).fill(' '))
14
+ for(let i = 0; i < arr.length; i++) {
15
+ const cur = mat[i]
16
+ for(let j = 0; j < arr[i].length; j++) {
17
+ mat[i][j] = arr[i][j]
18
19
20
+ const res = []
21
+ for(let j = 0; j < n; j++) {
22
+ const col = []
23
+ for(let i = 0; i < m; i++) {
24
+ col.push(mat[i][j])
25
26
+ res.push(col.join('').trimEnd())
27
28
29
+ return res
30
+};
0 commit comments