Skip to content

Commit 94ebf3a

Browse files
committed
Add solution 165.
1 parent 8747c01 commit 94ebf3a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
3+
/**
4+
* @param String $version1
5+
* @param String $version2
6+
* @return Integer
7+
*/
8+
function compareVersion($v1, $v2) {
9+
$i1 = 0; $i2 = 0; $n1 = 0; $n2 = 0;
10+
while ($i1 < strlen($v1) || $i2 < strlen($v2)) {
11+
while ($i1 < strlen($v1) && $v1[$i1] != '.') {
12+
$n1 = $n1 * 10 + ord($v1[$i1++]) - ord('0');
13+
}
14+
while ($i2 < strlen($v2) && $v2[$i2] != '.') {
15+
$n2 = $n2 * 10 + ord($v2[$i2++]) - ord('0');
16+
}
17+
if ($n1 > $n2) return 1;
18+
if ($n1 < $n2) return -1;
19+
$n1 = $n2 = 0;
20+
$i1++; $i2++;
21+
}
22+
return 0;
23+
}
24+
}

0 commit comments

Comments
 (0)