-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12 Integer to Roman.dart
59 lines (54 loc) · 1.01 KB
/
12 Integer to Roman.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Solution {
String intToRoman(int num) {
//List of Romans for Thousands
List<String> thousands = ["", "M", "MM", "MMM"];
//List of Romans for Hundreds
List<String> hundreds = [
"",
"C",
"CC",
"CCC",
"CD",
"D",
"DC",
"DCC",
"DCCC",
"CM"
];
//List of Romans for Tens
List<String> tens = [
"",
"X",
"XX",
"XXX",
"XL",
"L",
"LX",
"LXX",
"LXXX",
"XC"
];
//List of Romans for Ones
List<String> ones = [
"",
"I",
"II",
"III",
"IV",
"V",
"VI",
"VII",
"VIII",
"IX"
];
//Concatenation of all numbers' roman correspondent
return thousands[num ~/ 1000] + //get 1000th place
hundreds[num % 1000 ~/ 100] + //get 100th place
tens[num % 100 ~/ 10] + //get 10th place
ones[num % 10]; //get 1st place
}
}
void main() {
Solution sol = Solution();
print(sol.intToRoman(743));
}