站內搜尋

Wednesday, November 27, 2019

[LeetCode][PHP] #7 Reverse Integer

https://leetcode.com/problems/reverse-integer/

class Solution {
    function reverse($x) {
        $symbol = 1;
        if ($x < 0) $symbol = -1;
        $int = $x * $symbol;
        $int = strrev($int) * $symbol;
        if ($int > pow(2, 31) or $int < pow(2, 31)*-1) {
           return 0;
        }
        else {
            return $int;
        }
    }
}

No comments:

Post a Comment