在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
class Solution { /** * @param String $version1 * @param String $version2 * @return Integer */ function compareVersion($versionA, $versionB) { //$verListA = str_split($versionA); //$verListB = str_split($versionB); $dm = '.'; $verListA = explode($dm, (string)$versionA); $verListB = explode($dm, (string)$versionB); $len1 = count($verListA); $len2 = count($verListB); // echo $len1 . PHP_EOL; // echo $len2 . PHP_EOL; $max = max($len1, $len2); for ($i = 0; $i < $max; $i++) { $temp1 = 0; $temp2 = 0; if (i < $len1) { $temp1 = intval($verListA[$i]); } if (i < $len2) { $temp2 = intval($verListB[$i]); } if ($temp1 != $temp2) { return $temp1 > $temp2 ? 1 : -1; } } return 0; } }
|
2022-07-18
2022-08-17
2022-11-06
2022-08-17
2022-07-29
请发表评论