Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 97f869d

Browse files
author
Emre Tarhan
authored
Create solution.php
1 parent 93ed8ea commit 97f869d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎solution.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
class Solution {
3+
function romanToInt($s) {
4+
$romans = array(
5+
'M' => 1000,
6+
'CM' => 900,
7+
'D' => 500,
8+
'CD' => 400,
9+
'C' => 100,
10+
'XC' => 90,
11+
'L' => 50,
12+
'XL' => 40,
13+
'X' => 10,
14+
'IX' => 9,
15+
'V' => 5,
16+
'IV' => 4,
17+
'I' => 1,
18+
);
19+
$roman = 'III';
20+
$result = 0;
21+
22+
foreach ($romans as $key => $value) {
23+
while (strpos($roman, $key) === 0) {
24+
$result += $value;
25+
$roman = substr($roman, strlen($key));
26+
}
27+
}
28+
return $result;
29+
}
30+
}
31+
?>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /