Skip to content

Commit 0212990

Browse files
committed
feat: update solutions to lc problem: No.12
1 parent 7e91d18 commit 0212990

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

solution/0000-0099/0012.Integer to Roman/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,39 @@ func intToRoman(num int) string {
173173
}
174174
```
175175

176+
### **TypeScript**
177+
178+
```ts
179+
function intToRoman(num: number): string {
180+
const nums: number[] = [
181+
1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1,
182+
];
183+
const romans: string[] = [
184+
'M',
185+
'CM',
186+
'D',
187+
'CD',
188+
'C',
189+
'XC',
190+
'L',
191+
'XL',
192+
'X',
193+
'IX',
194+
'V',
195+
'IV',
196+
'I',
197+
];
198+
let ans: string = '';
199+
for (let i = 0; i < nums.length; ++i) {
200+
while (num >= nums[i]) {
201+
num -= nums[i];
202+
ans += romans[i];
203+
}
204+
}
205+
return ans;
206+
}
207+
```
208+
176209
### **...**
177210

178211
```

solution/0000-0099/0012.Integer to Roman/README_EN.md

+33
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,39 @@ func intToRoman(num int) string {
152152
}
153153
```
154154

155+
### **TypeScript**
156+
157+
```ts
158+
function intToRoman(num: number): string {
159+
const nums: number[] = [
160+
1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1,
161+
];
162+
const romans: string[] = [
163+
'M',
164+
'CM',
165+
'D',
166+
'CD',
167+
'C',
168+
'XC',
169+
'L',
170+
'XL',
171+
'X',
172+
'IX',
173+
'V',
174+
'IV',
175+
'I',
176+
];
177+
let ans: string = '';
178+
for (let i = 0; i < nums.length; ++i) {
179+
while (num >= nums[i]) {
180+
num -= nums[i];
181+
ans += romans[i];
182+
}
183+
}
184+
return ans;
185+
}
186+
```
187+
155188
### **...**
156189

157190
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function intToRoman(num: number): string {
2+
const nums: number[] = [
3+
1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1,
4+
];
5+
const romans: string[] = [
6+
'M',
7+
'CM',
8+
'D',
9+
'CD',
10+
'C',
11+
'XC',
12+
'L',
13+
'XL',
14+
'X',
15+
'IX',
16+
'V',
17+
'IV',
18+
'I',
19+
];
20+
let ans: string = '';
21+
for (let i = 0; i < nums.length; ++i) {
22+
while (num >= nums[i]) {
23+
num -= nums[i];
24+
ans += romans[i];
25+
}
26+
}
27+
return ans;
28+
}

0 commit comments

Comments
 (0)