Skip to content

Commit 6007260

Browse files
committed
🟡 Solve problem 12
1 parent e93cb27 commit 6007260

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎swift/12.swift‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
func intToRoman(_ num: Int) -> String {
3+
let romanSymbols = [
4+
("M", 1000),
5+
("CM", 900),
6+
("D", 500),
7+
("CD", 400),
8+
("C", 100),
9+
("XC", 90),
10+
("L", 50),
11+
("XL", 40),
12+
("X", 10),
13+
("IX", 9),
14+
("V", 5),
15+
("IV", 4),
16+
("I", 1)
17+
]
18+
19+
var number = num
20+
var result = ""
21+
22+
for (symbol, value) in romanSymbols {
23+
while number >= value {
24+
result += symbol
25+
number -= value
26+
}
27+
}
28+
29+
return result
30+
}
31+
}

0 commit comments

Comments
 (0)