File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed
rearrange-spaces-between-words Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ leetcode 测试
10
10
11
11
##### 包含的内容如下
12
12
13
+ https://leetcode.cn/problems/rearrange-spaces-between-words/
14
+
13
15
https://leetcode.cn/problems/count-complete-tree-nodes/
14
16
15
17
https://leetcode.cn/problems/broken-calculator
Original file line number Diff line number Diff line change 22
22
"rules" : {
23
23
"include" : [],
24
24
"exclude" : [
25
- " no-explicit-any"
25
+ " no-explicit-any" ,
26
+ " ban-ts-comment"
26
27
]
27
28
}
28
29
},
Original file line number Diff line number Diff line change
1
+ // deno-lint-ignore-file ban-ts-comment
2
+ export default function reorderSpaces ( text : string ) : string {
3
+ const words = text . split ( / \s + / g) . filter ( Boolean ) ;
4
+
5
+ //@ts -ignore
6
+ const spaces = Array . prototype . reduce . call (
7
+ text ,
8
+ //@ts -ignore
9
+ ( a , v ) => a + Number ( v === " " ) ,
10
+ 0
11
+ ) as number ;
12
+
13
+ if ( words . length <= 1 ) return words . join ( "" ) + " " . repeat ( spaces ) ;
14
+ const sep = " " . repeat ( Math . floor ( spaces / ( words . length - 1 ) ) ) ;
15
+
16
+ return words . join ( sep ) + " " . repeat ( spaces % ( words . length - 1 ) ) ;
17
+ }
You can’t perform that action at this time.
0 commit comments