PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php class Solution { /** * @param String $s * @return Integer */ function myAtoi($s) { $arr = str_split($s); $sign = null; $result = 0; foreach ($arr as $item) { if (!isset($sign) && in_array($item, ['-', '+'])) { $sign = $item == '-'; } if (is_numeric($item)) { $result = $result * 10 + $item; } } return $sign ? -$result : $result; } } echo (new Solution())->myAtoi(" -88827 5655 U");
Show:  
Copy Clear