Submission Detail

3999 / 3999 test cases passed.
Status:

Accepted

Runtime: 14 ms
Memory Usage: 44.8 MB
Submitted: 1 week, 3 days ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0.0
2.5
5.0
7.5
10.0
12.5
15.0
17.5
20.0
22.5
25.0
27.5
10
20
30
40
java
You are here!
Your runtime beats 8.48 % of java submissions.
Runtime (ms)
Distribution (%)

0
5
10
15
20
25
10
20
30
40
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

41500
41750
42000
42250
42500
42750
43000
43250
43500
43750
44000
2
4
6
8
java
Memory (KB)
Distribution (%)

41500
41750
42000
42250
42500
42750
43000
43250
43500
43750
44000
2.5
5.0
7.5
Zoom area by dragging across this chart

Invite friends to challenge Roman to Integer


Submitted Code: 1 week, 3 days ago

Language: java

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class Solution {
public int romanToInt(String s) {
int integer = 0;
int index = 0;
while (index < s.length() && s.charAt(index) == 'M') {
integer += 1000;
index++;
}
if (index < s.length() && s.charAt(index) == 'C' && index+1 < s.length() && s.charAt(index+1) == 'M') {
integer += 900;
index += 2;
}
if (index < s.length() && s.charAt(index) == 'D') {
integer += 500;
index++;
}
// 400
if (index < s.length() && s.charAt(index) == 'C' && (index+1) < s.length() && s.charAt(index+1) == 'D') {
integer += 400;
index += 2;
}
while (index < s.length() && s.charAt(index) == 'C') {
integer += 100;
index++;
}
if (index < s.length() && s.charAt(index) == 'X' && (index+1) < s.length() && s.charAt(index+1) == 'C') {
integer += 90;
index += 2;
}
if (index < s.length() && s.charAt(index) == 'L') {
integer += 50;
index++;
}
if (index < s.length() && s.charAt(index) == 'X' && (index+1) < s.length() && s.charAt(index+1) == 'L') {
integer += 40;
index += 2;
}
while (index < s.length() && s.charAt(index) == 'X') {
integer += 10;
index++;
}
if (index < s.length() && s.charAt(index) == 'I' && (index+1) < s.length() && s.charAt(index+1) == 'X') {
integer += 9;
index += 2;
}
if (index < s.length() && s.charAt(index) == 'V') {
integer += 5;
index++;
}
if (index < s.length() && s.charAt(index) == 'I' && (index+1) < s.length() && s.charAt(index+1) == 'V') {
integer += 4;
index += 2;
}
while (index < s.length() && s.charAt(index) == 'I') {
integer += 1;
index++;
}
System.out.println(integer);
return integer;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX