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 ce69dda commit e1d15daCopy full SHA for e1d15da
1324.竖直打印单词.js
@@ -0,0 +1,31 @@
1
+/**
2
+ * 1. 找到最大单词长度
3
+ * 2. 以 0 ~ 最大长度 为下标遍历各单词
4
+ * 3. 删除末尾空格
5
+ */
6
+
7
8
+ * @param {string} s
9
+ * @return {string[]}
10
11
+var printVertically = function(s) {
12
+ const words = s.split(' ');
13
+ let max = 0;
14
+ for (const word of words) {
15
+ max = Math.max(max, word.length);
16
+ }
17
18
+ const result = [];
19
+ for (let i = 0; i < max; i++) {
20
+ result[i] = [];
21
+ for (let j = 0; j < words.length; j++) {
22
+ result[i].push(words[j][i] || ' ');
23
24
+ while (result[i][result[i].length - 1] === ' ') {
25
+ result[i].pop();
26
27
+ result[i] = result[i].join('');
28
29
30
+ return result;
31
+};
0 commit comments