Skip to content

Commit caa9ede

Browse files
committed
feat: add solution to lc problem: No.1451
1 parent ad658f2 commit caa9ede

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

solution/1400-1499/1451.Rearrange Words in a Sentence/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ class Solution {
162162
}
163163
```
164164

165+
### **TypeScript**
166+
167+
```ts
168+
function arrangeWords(text: string): string {
169+
let words: string[] = text.split(" ");
170+
words[0] = words[0].toLowerCase();
171+
words.sort((a, b) => a.length - b.length);
172+
words[0] = words[0].charAt(0).toUpperCase() + words[0].slice(1);
173+
return words.join(" ");
174+
}
175+
```
176+
165177
### **...**
166178

167179
```

solution/1400-1499/1451.Rearrange Words in a Sentence/README_EN.md

+12
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ class Solution {
147147
}
148148
```
149149

150+
### **TypeScript**
151+
152+
```ts
153+
function arrangeWords(text: string): string {
154+
let words: string[] = text.split(" ");
155+
words[0] = words[0].toLowerCase();
156+
words.sort((a, b) => a.length - b.length);
157+
words[0] = words[0].charAt(0).toUpperCase() + words[0].slice(1);
158+
return words.join(" ");
159+
}
160+
```
161+
150162
### **...**
151163

152164
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function arrangeWords(text: string): string {
2+
let words: string[] = text.split(" ");
3+
words[0] = words[0].toLowerCase();
4+
words.sort((a, b) => a.length - b.length);
5+
words[0] = words[0].charAt(0).toUpperCase() + words[0].slice(1);
6+
return words.join(" ");
7+
}

0 commit comments

Comments
 (0)